소스 검색

Fixed possible unhandled exception on WebSocket close

Paul-Louis Ageneau 3 년 전
부모
커밋
1f78ab7824
1개의 변경된 파일6개의 추가작업 그리고 1개의 파일을 삭제
  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);
 	}
 }