We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4e6769f commit 90d6626Copy full SHA for 90d6626
ext/mysql2/client.c
@@ -477,10 +477,13 @@ static VALUE disconnect_and_raise(VALUE self, VALUE error) {
477
wrapper->active_thread = Qnil;
478
wrapper->connected = 0;
479
480
- /* manually close the socket for read/write
481
- this feels dirty, but is there another way? */
482
- close(wrapper->client->net.fd);
483
- wrapper->client->net.fd = -1;
+ /* Invalidate the MySQL socket to prevent further communication.
+ * The GC will come along later and call mysql_close to free it.
+ */
+ if (invalidate_fd(wrapper->client->net.fd) == Qfalse) {
484
+ fprintf(stderr, "[WARN] mysql2 failed to invalidate FD safely, closing unsafely\n");
485
+ close(wrapper->client->net.fd);
486
+ }
487
488
rb_exc_raise(error);
489
0 commit comments