@@ -46,6 +46,7 @@ struct nogvl_connect_args {
46
46
struct nogvl_send_query_args {
47
47
MYSQL * mysql ;
48
48
VALUE sql ;
49
+ mysql_client_wrapper * wrapper ;
49
50
};
50
51
51
52
/*
@@ -250,6 +251,17 @@ static VALUE nogvl_send_query(void *ptr) {
250
251
return rv == 0 ? Qtrue : Qfalse ;
251
252
}
252
253
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
+
253
265
/*
254
266
* even though we did rb_thread_select before calling this, a large
255
267
* 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) {
446
458
args .sql = rb_str_export_to_enc (args .sql , conn_enc );
447
459
#endif
448
460
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 );
454
463
455
464
#ifndef _WIN32
456
465
if (!async ) {
0 commit comments