Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.
Python asraudiochineseemotion-recognitionfunasrmcp-servermultilingual-asropenai-compatible-apiparaformerpunctuationpytorchreal-time-asrspeaker-diarizationspeech-recognitionspeech-to-textstreaming-asrtranscriptionvllmvoice-activity-detectionwhisper-alternative
add lock for remove_hdl
雾聪242a98e70e12
diff --git a/funasr/runtime/websocket/websocket-server-2pass.cpp b/funasr/runtime/websocket/websocket-server-2pass.cppindex 201b43902..14c2e35e8 100644--- a/funasr/runtime/websocket/websocket-server-2pass.cpp+++ b/funasr/runtime/websocket/websocket-server-2pass.cpp@@ -299,9 +299,10 @@ void WebSocketServer::check_and_clean_connection() {iter++;}for (auto hdl : to_remove) {- remove_hdl(hdl, data_map);- //LOG(INFO) << "remove one connection ";-+ {+ unique_lock lock(m_lock);+ remove_hdl(hdl, data_map);+ }}}}diff --git a/funasr/runtime/websocket/websocket-server.cpp b/funasr/runtime/websocket/websocket-server.cppindex f9febbd35..36af3c234 100644--- a/funasr/runtime/websocket/websocket-server.cpp+++ b/funasr/runtime/websocket/websocket-server.cpp@@ -149,7 +149,6 @@ void WebSocketServer::on_close(websocketpp::connection_hdl hdl) {unique_lock guard_decoder(*(data_msg->thread_lock));data_msg->msg["is_eof"]=true;guard_decoder.unlock();- // data_map.erase(hdl); // remove data vector when connection is closedLOG(INFO) << "on_close, active connections: " << data_map.size();}@@ -158,7 +157,6 @@ void remove_hdl(websocketpp::connection_hdl hdl,std::map<websocketpp::connection_hdl, std::shared_ptr<FUNASR_MESSAGE>,std::owner_less<websocketpp::connection_hdl>>& data_map) {-std::shared_ptr<FUNASR_MESSAGE> data_msg = nullptr;auto it_data = data_map.find(hdl);if (it_data != data_map.end()) {@@ -214,8 +212,10 @@ void WebSocketServer::check_and_clean_connection() {iter++;}for (auto hdl : to_remove) {- remove_hdl(hdl, data_map);- //LOG(INFO) << "remove one connection ";+ {+ unique_lock lock(m_lock);+ remove_hdl(hdl, data_map);+ }}}}@@ -230,7 +230,11 @@ void WebSocketServer::on_message(websocketpp::connection_hdl hdl,auto it_data = data_map.find(hdl);if (it_data != data_map.end()) {msg_data = it_data->second;+ } else{+ lock.unlock();+ return;}+std::shared_ptr<std::vector<char>> sample_data_p = msg_data->samples;std::shared_ptr<websocketpp::lib::mutex> thread_lock_p = msg_data->thread_lock;