Ver Fonte

Fixed possible unhandled exception on WebSocket close

Paul-Louis Ageneau há 3 anos atrás
pai
commit
1f78ab7824
1 ficheiros alterados com 6 adições e 1 exclusões
  1. 6 1
      src/impl/wstransport.cpp

+ 6 - 1
src/impl/wstransport.cpp

@@ -173,8 +173,13 @@ void WsTransport::incoming(message_ptr message) {
 
 
 void WsTransport::close() {
 void WsTransport::close() {
 	if (state() == State::Connected) {
 	if (state() == State::Connected) {
-		sendFrame({CLOSE, NULL, 0, true, mIsClient});
 		PLOG_INFO << "WebSocket closing";
 		PLOG_INFO << "WebSocket closing";
+		try {
+			sendFrame({CLOSE, NULL, 0, true, mIsClient});
+		} catch (const std::exception &e) {
+			// Ignore error as the connection might not be open anymore
+			PLOG_DEBUG << "Unable to send WebSocket close frame: " << e.what();
+		}
 		changeState(State::Disconnected);
 		changeState(State::Disconnected);
 	}
 	}
 }
 }