Skip to content

Commit 90d6626

Browse files
committed
Call invalidate_fd in disconnect_and_raise
1 parent 4e6769f commit 90d6626

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ext/mysql2/client.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,13 @@ static VALUE disconnect_and_raise(VALUE self, VALUE error) {
477477
wrapper->active_thread = Qnil;
478478
wrapper->connected = 0;
479479

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;
480+
/* Invalidate the MySQL socket to prevent further communication.
481+
* The GC will come along later and call mysql_close to free it.
482+
*/
483+
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+
}
484487

485488
rb_exc_raise(error);
486489

0 commit comments

Comments
 (0)