@@ -164,26 +164,19 @@ static void *nogvl_connect(void *ptr) {
164164
165165static void * nogvl_close (void * ptr ) {
166166 mysql_client_wrapper * wrapper ;
167- #ifndef _WIN32
168- int flags ;
169- #endif
170167 wrapper = ptr ;
171168 if (wrapper -> connected ) {
172169 wrapper -> active_thread = Qnil ;
173170 wrapper -> connected = 0 ;
174- /*
175- * we'll send a QUIT message to the server, but that message is more of a
176- * formality than a hard requirement since the socket is getting shutdown
177- * anyways, so ensure the socket write does not block our interpreter
178- *
179- *
180- * if the socket is dead we have no chance of blocking,
181- * so ignore any potential fcntl errors since they don't matter
182- */
183171#ifndef _WIN32
184- flags = fcntl (wrapper -> client -> net .fd , F_GETFL );
185- if (flags > 0 && !(flags & O_NONBLOCK ))
186- fcntl (wrapper -> client -> net .fd , F_SETFL , flags | O_NONBLOCK );
172+ /* Call close() on the socket before calling mysql_close(). This prevents
173+ * mysql_close() from sending a mysql-QUIT or from calling shutdown() on
174+ * the socket. The difference is that close() will drop this process's
175+ * reference to the socket only, while a QUIT or shutdown() would render
176+ * the underlying connection unusable, interrupting other processes which
177+ * share this object across a fork().
178+ */
179+ close (wrapper -> client -> net .fd );
187180#endif
188181
189182 mysql_close (wrapper -> client );
0 commit comments