Skip to content

Commit 8e81dcb

Browse files
Eric Wongbrianmario
Eric Wong
authored andcommitted
retry connect if interrupted by signals
The MySQL client libraries normally retry system calls when interrupted by signals. The lone exception I've found is in the (infrequent) connection setup where it'll propagate the connect(2) syscall error all the way back up to the caller. Fortunately inspection of the MySQL client library reveals it properly preserves the global "errno" variable even with debugging enabled. Note that the net.last_errno member does NOT correspond to the system "errno".
1 parent 8bfbfa2 commit 8e81dcb

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ext/mysql2/client.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <mysql2_ext.h>
22
#include <client.h>
3+
#include <errno.h>
34

45
VALUE cMysql2Client;
56
extern VALUE mMysql2, cMysql2Error;
@@ -96,10 +97,12 @@ static VALUE nogvl_connect(void *ptr) {
9697
struct nogvl_connect_args *args = ptr;
9798
MYSQL *client;
9899

99-
client = mysql_real_connect(args->mysql, args->host,
100-
args->user, args->passwd,
101-
args->db, args->port, args->unix_socket,
102-
args->client_flag);
100+
do {
101+
client = mysql_real_connect(args->mysql, args->host,
102+
args->user, args->passwd,
103+
args->db, args->port, args->unix_socket,
104+
args->client_flag);
105+
} while (! client && errno == EINTR && (errno = 0) == 0);
103106

104107
return client ? Qtrue : Qfalse;
105108
}

0 commit comments

Comments
 (0)