From e8cc7be8fdd62a2188cda78934e300a4b06bc5c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Wed, 18 Aug 2021 23:29:05 +0200 Subject: [PATCH] Added non-blocking calls to 'SSL_shutdown' for sending final 'close_notify' required by SSL standard --- lib/mysql_data_stream.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/mysql_data_stream.cpp b/lib/mysql_data_stream.cpp index 8eb58b61c..1324e8d96 100644 --- a/lib/mysql_data_stream.cpp +++ b/lib/mysql_data_stream.cpp @@ -366,6 +366,14 @@ MySQL_Data_Stream::~MySQL_Data_Stream() { } if ( (myconn) && (myds_type==MYDS_FRONTEND) ) { delete myconn; myconn=NULL; } if (encrypted) { + if (ssl) { + // NOTE: SSL standard requires a final 'close_notify' alert on socket + // shutdown. But for avoiding any kind of locking IO waiting for the + // other part, we perform a 'quiet' shutdown. For more context see + // MYSQL #29579. + SSL_set_quiet_shutdown(ssl, 1); + SSL_shutdown(ssl); + } if (ssl) SSL_free(ssl); /* SSL_free() should also take care of these @@ -445,7 +453,12 @@ void MySQL_Data_Stream::shut_hard() { proxy_debug(PROXY_DEBUG_NET, 4, "Shutdown hard fd=%d. Session=%p, DataStream=%p\n", fd, sess, this); set_net_failure(); if (encrypted) { + // NOTE: SSL standard requires a final 'close_notify' alert on socket + // shutdown. But for avoiding any kind of locking IO waiting for the + // other part, we perform a 'quiet' shutdown. For more context see + // MYSQL #29579. SSL_set_quiet_shutdown(ssl, 1); + SSL_shutdown(ssl); } if (fd >= 0) { shutdown(fd, SHUT_RDWR);