From 64a14588477245c2a64a202c20ef80a88be0302f Mon Sep 17 00:00:00 2001 From: Monty Date: Fri, 7 Mar 2025 19:24:10 +0200 Subject: [PATCH] Ensure that ER_CONNECTION_KILLED error message is not lost my_real_read() detects if the connection was killed and sets error to ER_CONNECTION_KILLED. However net_real_write() overrides the error with ER_NET_READ_INTERRUPTED or ER_NET_READ_ERROR when it tries to send the 'Connection was killed' to the user on a closed connection. Fixed by not overwriting the original error code if the connection was shutdown. Rewiewed-by: Kristian Nielsen --- sql/net_serv.cc | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/sql/net_serv.cc b/sql/net_serv.cc index e0fad74288a..35b2a24a2d2 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -773,18 +773,22 @@ net_real_write(NET *net,const uchar *packet, size_t len) } #endif /* !defined(MYSQL_SERVER) */ net->error= 2; /* Close socket */ - net->last_errno= (interrupted ? ER_NET_WRITE_INTERRUPTED : - ER_NET_ERROR_ON_WRITE); -#ifdef MYSQL_SERVER - if (global_system_variables.log_warnings > 3) + + if (net->vio->state != VIO_STATE_SHUTDOWN || net->last_errno == 0) { - sql_print_warning("Could not write packet: fd: %lld state: %d " - "errno: %d vio_errno: %d length: %ld", - (longlong) vio_fd(net->vio), (int) net->vio->state, - vio_errno(net->vio), net->last_errno, - (ulong) (end-pos)); - } + net->last_errno= (interrupted ? ER_NET_WRITE_INTERRUPTED : + ER_NET_ERROR_ON_WRITE); +#ifdef MYSQL_SERVER + if (global_system_variables.log_warnings > 3) + { + sql_print_warning("Could not write packet: fd: %lld state: %d " + "errno: %d vio_errno: %d length: %ld", + (longlong) vio_fd(net->vio), (int) net->vio->state, + vio_errno(net->vio), net->last_errno, + (ulong) (end-pos)); + } #endif + } MYSQL_SERVER_my_error(net->last_errno, MYF(0)); break; }