[debian-mysql] Bug#715065: libmysqlclient16: random "Lost connection" errors due to failure of handling EINTR correctly
Marc Lehmann
debian-reportbug at plan9.de
Sat Jul 6 04:56:44 UTC 2013
Package: libmysqlclient16
Version: 5.1.66-0+squeeze1
Severity: normal
Dear Maintainer,
In a program that forks a lot of other programs I randomly get spurious "Lost connection" errors
from mysql. The server logs no message and doesn't crash.
strace'ing shows this to be a bug in libmysqlclient (or possibly
DBD::mysql, but that is unlikely as all sql execution is handled by
libmysqlclient), not handling EINTR correctly:
write(4, "X\0\0\0\3insert ignore into comp (worse, better) values ('...', '...')", 92) = 92
read(4, 0x151f160, 16384) = -1 EINTR (Interrupted system call)
--- SIGCHLD (Child exited) @ 0 (0) ---
read(4, 0x151f160, 16384) = -1 EINTR (Interrupted system call)
--- SIGCHLD (Child exited) @ 0 (0) ---
read(4, 0x151f160, 16384) = -1 EINTR (Interrupted system call)
--- SIGCHLD (Child exited) @ 0 (0) ---
write(2, "DBD::mysql::st execute failed: Lost connection to MySQL server during query at convert line 53.\n", 105) = 105
The first write sends an sql query to mysql (on fd#4). mysql then tries to
read the results, but the process gets interrupted because a child process
exits, causing SIGCHLD to be received and read returning with EINTR.
Mysqlclient tries three times to read results, and apparently gives up,
wrongly causing a "Lost connection" error.
Since this is hard to replicate consistently and the bug looks obvious
enough, I didn't try to make a test script.
A quick grep through "mysql-5.5-5.5.31+dfsg" sources shows, as likely
culprit (I am not an expert on mysql) the function net_safe_read in
./sql/net_serv.cc, which retries up to "net->retry_count" times on EINTR
and then gives up. This is a bug, an application always has to retry on
EINTR, otherwise you get spurious errors as in this case.
Other functions such as net_real_write contain the same faulty logic
of retrying EINTR only a fixed number of times. There might be more
occurances of this (I guess most if not all uses of vio_should_retry are
broken - retrying on EAGAIN is quite useless waste of cpu and retrying
only a few times on EINTR is a bug).
-- System Information:
Debian Release: 7.1
APT prefers stable
APT policy: (990, 'stable'), (500, 'unstable'), (500, 'testing'), (500, 'oldstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 3.9-0.bpo.1-amd64 (SMP w/12 CPU cores)
Locale: LANG=C, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages libmysqlclient16 depends on:
ii libc6 2.13-38
ii mysql-common 5.5.31+dfsg-0+wheezy1
ii zlib1g 1:1.2.7.dfsg-13
libmysqlclient16 recommends no packages.
libmysqlclient16 suggests no packages.
-- no debconf information
More information about the pkg-mysql-maint
mailing list