Skip to content

Commit 69be46c

Browse files
committed
make sure we clean up if we were interrupted while processing a query on Windows
1 parent 2481815 commit 69be46c

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

ext/mysql2/client.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,27 @@ static VALUE do_query(void *args) {
388388

389389
return Qnil;
390390
}
391+
#else
392+
static VALUE finish_and_mark_inactive(void *args) {
393+
VALUE self;
394+
MYSQL_RES *result;
395+
396+
self = (VALUE)args;
397+
398+
GET_CLIENT(self);
399+
400+
if (wrapper->active) {
401+
// if we got here, the result hasn't been read off the wire yet
402+
// so lets do that and then throw it away because we have no way
403+
// of getting it back up to the caller from here
404+
result = (MYSQL_RES *)rb_thread_blocking_region(nogvl_store_result, wrapper, RUBY_UBF_IO, 0);
405+
mysql_free_result(result);
406+
407+
wrapper->active = 0;
408+
}
409+
410+
return Qnil;
411+
}
391412
#endif
392413

393414
static VALUE rb_mysql_client_query(int argc, VALUE * argv, VALUE self) {
@@ -451,7 +472,7 @@ static VALUE rb_mysql_client_query(int argc, VALUE * argv, VALUE self) {
451472
}
452473
#else
453474
// this will just block until the result is ready
454-
return rb_mysql_client_async_result(self);
475+
return rb_ensure(rb_mysql_client_async_result, self, finish_and_mark_inactive, self);
455476
#endif
456477
}
457478

0 commit comments

Comments
 (0)