Browse Source

Merge pull request #673 from paullouisageneau/fix-ws-exception-on-close

Fix possible unhandled exception on WebSocket close
Paul-Louis Ageneau 3 years ago
parent
commit
7c667bceb1
1 changed files with 6 additions and 1 deletions
  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() {
 	if (state() == State::Connected) {
-		sendFrame({CLOSE, NULL, 0, true, mIsClient});
 		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);
 	}
 }