Bug #5449 Client hangs if connection to remote server is dropped
Submitted: 7 Sep 2004 12:47 Modified: 21 Aug 2006 17:33
Reporter: [ name withheld ] Email Updates:
Status: Duplicate Impact on me:
Category:MySQL Server: Command-line Clients Severity:S1 (Critical)
Version:3.23.58,4.1.5 OS:Linux (Fedora Core)
Assigned to: CPU Architecture:Any

[7 Sep 2004 12:47] [ name withheld ]
When database is open, libmysql does not handle the lost of physical connection properly.

Functions (examples: mysql_query(), mysql_ping()) will hang and won't return any result until connection is restored.

Different timeouts do not help to resolve the problem.

How to repeat:
1. Connect client to the server.
2. Select database.
3. Disconnect the server from the LAN by disconnecting cable or issuing command 'ifdown'.
4. Functions mysql_ping(), mysql_query() hang
5. Connect the server back
6. Functions mysql_ping(), mysql_query() returns

Suggested fix:
Make timeouts work?
Put read/write timeouts on sockets?
[28 Sep 2004 14:48] Matthew Lord

I'm having problems repeating this as you can see here:

/usr/local/mysql-3.23.58-pc-linux-i686/bin/mysqladmin --port=3999 ping -h
/usr/local/mysql-3.23.58-pc-linux-i686/bin/mysqladmin: connect to server at '' failed
error: 'Can't connect to MySQL server on '' (113)'
Check that mysqld is running on and that the port is 3999.
You can check this by doing 'telnet 3999'

Is there anything that I may be missing here?  I was unable to repeat it using a unix
domain socket as well.  When specifying a bad socket file it immediately returns.

Best Regards
[1 Oct 2004 9:03] [ name withheld ]
The problem appears when you are already connected to the database and cable is being disconnected.

Here is an example of a program that connects to the server, opens the database and then it is going to query (mysql_query) or ping(mysql_ping). If there is a link, then it should output "+", otherwise "-".

Steps to repeat bug:
1. Change settings for your host, database, and table (if you are going to check mysql_query also)
2. Compile, Run
You should see characters "+" on the screen
3. Disconnect physical cable from network card (same affect with 'ifdown eth0')
You should see characters "-" on the screen, but this does not happen - BUG!
4. Connect physical cable back
You should see characters "+" on the screen again in a while (it may take more than one minute), since connection is back

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <mysql/mysql.h>

// put your host and database settings
#define HOST ""
#define DATABASE "mydatabase"

#define VER_QUERY 1

MYSQL *mysql;

int uid;
char clause[1024];
char uname[5];
char to[5]="\0\0\0\0";

int main()
    mysql = mysql_init(NULL);
    if (!(mysql_real_connect(mysql,HOST,"root","password",DATABASE,0,0,CLIENT_SSL)))

#ifdef VER_QUERY
	if (!mysql_query(mysql,"SELECT * FROM settings;")){
	    res = mysql_use_result(mysql);
	}else {
	    printf("[%d %s]\n", mysql_errno(mysql), mysql_error(mysql));
// use ping only
	if(mysql_ping(mysql)) printf("-");
	else printf("+");

[1 Oct 2004 22:42] Matthew Lord
I was able to verify this using the provided test app and disconnecting the ethernet cable on the 

client machine:
Darwin silverbullet 7.5.0 Darwin Kernel Version 7.5.0: Thu Aug  5 19:26:16 PDT 2004; root:xnu/
xnu-517.7.21.obj~3/RELEASE_PPC  Power Macintosh powerpc

server machines:
Linux booty 2.4.21 #12 SMP Thu Aug 14 00:49:40 EDT 2003 i686 i686 i386 GNU/Linux
Windows 2000 SMP

The client machine was running 4.1.5-gamma, the Linux server was running 4.1.5 and the 
windows 2000 server was running 4.0.20.
[2 Nov 2004 11:48] [ name withheld ]
verified too on linux redhat 7.3
[27 Jul 2005 12:42] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

[28 Sep 2005 7:58] Sergei Golubchik
see also the thread in internals that starts from http://lists.mysql.com/internals/26739
BUG#4143, BUG#11774
[21 Aug 2006 17:33] Tomash Brechko
This bug is a duplicate of bug#9678.