Skip to content

Commit d7091cd

Browse files
committed
wrap send_query with rb_rescue2 as well, lets see if this catches the race condition
1 parent 4982d27 commit d7091cd

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

ext/mysql2/client.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct nogvl_connect_args {
4646
struct nogvl_send_query_args {
4747
MYSQL *mysql;
4848
VALUE sql;
49+
mysql_client_wrapper *wrapper;
4950
};
5051

5152
/*
@@ -250,6 +251,17 @@ static VALUE nogvl_send_query(void *ptr) {
250251
return rv == 0 ? Qtrue : Qfalse;
251252
}
252253

254+
static VALUE do_send_query(void *args) {
255+
struct nogvl_send_query_args *query_args = args;
256+
mysql_client_wrapper *wrapper = query_args->wrapper;
257+
if (rb_thread_blocking_region(nogvl_send_query, args, RUBY_UBF_IO, 0) == Qfalse) {
258+
// an error occurred, we're not active anymore
259+
MARK_CONN_INACTIVE(self);
260+
return rb_raise_mysql2_error(wrapper);
261+
}
262+
return Qnil;
263+
}
264+
253265
/*
254266
* even though we did rb_thread_select before calling this, a large
255267
* response can overflow the socket buffers and cause us to eventually
@@ -446,11 +458,8 @@ static VALUE rb_mysql_client_query(int argc, VALUE * argv, VALUE self) {
446458
args.sql = rb_str_export_to_enc(args.sql, conn_enc);
447459
#endif
448460

449-
if (rb_thread_blocking_region(nogvl_send_query, &args, RUBY_UBF_IO, 0) == Qfalse) {
450-
// an error occurred, we're not active anymore
451-
MARK_CONN_INACTIVE(self);
452-
return rb_raise_mysql2_error(wrapper);
453-
}
461+
args.wrapper = wrapper;
462+
rb_rescue2(do_send_query, (VALUE)&args, disconnect_and_raise, self, rb_eException, (VALUE)0);
454463

455464
#ifndef _WIN32
456465
if (!async) {

0 commit comments

Comments
 (0)