From d2a787805a07e2b4218cc6ed9be7acefed216629 Mon Sep 17 00:00:00 2001 From: Miguel Portilla Date: Fri, 15 Apr 2016 12:54:50 -0400 Subject: [PATCH] Fix secured Websocket closing. Websocketpp was incorrectly handling close before or during protocol negotiation. This issue addresses lingering CLOSE_WAIT file descriptors. --- src/websocketpp_02/src/connection.hpp | 2 ++ src/websocketpp_02/src/roles/server.hpp | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/websocketpp_02/src/connection.hpp b/src/websocketpp_02/src/connection.hpp index a03a88a6ee..df97c384e5 100644 --- a/src/websocketpp_02/src/connection.hpp +++ b/src/websocketpp_02/src/connection.hpp @@ -1404,6 +1404,8 @@ public: log_close_result(); } + else + m_state = session::state::CLOSED; // finally remove this connection from the endpoint's list. This will // remove the last shared pointer to the connection held by WS++. If we diff --git a/src/websocketpp_02/src/roles/server.hpp b/src/websocketpp_02/src/roles/server.hpp index 83858f03cf..ea37fc9b2b 100644 --- a/src/websocketpp_02/src/roles/server.hpp +++ b/src/websocketpp_02/src/roles/server.hpp @@ -914,7 +914,8 @@ void server::connection::handle_write_response( return; } - if (m_response.get_status_code() != http::status_code::SWITCHING_PROTOCOLS) { + if (m_response.get_status_code() != http::status_code::SWITCHING_PROTOCOLS || + m_connection.m_state == session::state::CLOSED) { if (m_version == -1) { // if this was not a websocket connection, we have written // the expected response and the connection can be closed.