雾聪
2023-11-30 467186eec4ffee2ca9d4d5c61b225e8cc2373585
fix bug of websocket lock blocking
2个文件已修改
9 ■■■■ 已修改文件
runtime/websocket/bin/websocket-server-2pass.cpp 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
runtime/websocket/bin/websocket-server.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
runtime/websocket/bin/websocket-server-2pass.cpp
@@ -98,8 +98,8 @@
    std::string wav_format,
    FUNASR_HANDLE& tpass_online_handle) {
  // lock for each connection
  scoped_lock guard(thread_lock);
  if(!tpass_online_handle){
    scoped_lock guard(thread_lock);
      LOG(INFO) << "tpass_online_handle  is free, return";
      msg["access_num"]=(int)msg["access_num"]-1;
      return;
@@ -128,10 +128,12 @@
                                       hotwords_embedding, itn);
        } else {
          scoped_lock guard(thread_lock);
          msg["access_num"]=(int)msg["access_num"]-1;
          return;
        }
      } catch (std::exception const& e) {
        scoped_lock guard(thread_lock);
        LOG(ERROR) << e.what();
        msg["access_num"]=(int)msg["access_num"]-1;
        return;
@@ -162,10 +164,12 @@
                                       wav_format, (ASR_TYPE)asr_mode_,
                                       hotwords_embedding, itn);
        } else {
          scoped_lock guard(thread_lock);
          msg["access_num"]=(int)msg["access_num"]-1;     
          return;
        }
      } catch (std::exception const& e) {
        scoped_lock guard(thread_lock);
        LOG(ERROR) << e.what();
        msg["access_num"]=(int)msg["access_num"]-1;
        return;
@@ -209,6 +213,7 @@
  } catch (std::exception const& e) {
    std::cerr << "Error: " << e.what() << std::endl;
  }
  scoped_lock guard(thread_lock);
  msg["access_num"]=(int)msg["access_num"]-1;
 
}
runtime/websocket/bin/websocket-server.cpp
@@ -68,7 +68,6 @@
                                 int audio_fs,
                                 std::string wav_format,
                                 FUNASR_DEC_HANDLE& decoder_handle) {
  scoped_lock guard(thread_lock);
  try {
    int num_samples = buffer.size();  // the size of the buf
@@ -130,6 +129,7 @@
  } catch (std::exception const& e) {
    std::cerr << "Error: " << e.what() << std::endl;
  }
  scoped_lock guard(thread_lock);
  msg["access_num"]=(int)msg["access_num"]-1;
}