Open
Description
🐛 Bug
To Reproduce
Steps to reproduce the behavior (always include the command you ran):
- Run cmd
./funasr-http-server --vad-dir ~/.cache/modelscope/hub/models/iic/speech_fsmn_vad_zh-cn-16k-common-pytorch --model-dir ~/.cache/modelscope/hub/models/iic/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch --itn-dir '' --lm-dir '' --hotword ../my_hotword.txt --port 10001 --io-thread-num 3
- See error: 启动命令中的 io-thread-num 参数设置的3,用curl发送3次请求后,再次请求就无法成功,把这个改成8,就能请求成功8次。
Code sample
- 在debug研究源码后发现,connection.cpp的do_write函数,一直无法执行到
data_msg->sem_resultok.release();
导致连接无法被正常释放,就会使连接池被用完,后续请求也就无法成功。 - 于是我将这个异步函数改成同步的,就能正常连续请求了,应该就是信号量被释放了,但是还是想明白这个异步函数为啥没被正常完整执行,下面是我改的代码:
void connection::do_write()
{
try {
// 同步写入数据
asio::write(socket_, reply_.to_buffers());
// 关闭连接
asio::error_code shutdown_ec;
socket_.shutdown(asio::ip::tcp::socket::shutdown_both, shutdown_ec);
if (shutdown_ec) {
std::cerr << "Socket shutdown error: " << shutdown_ec.message() << std::endl;
}
// 释放信号量
data_msg->sem_resultok.release();
} catch (const std::exception& e) {
std::cerr << "Write failed: " << e.what() << std::endl;
data_msg->sem_resultok.release(); // 仍然释放信号量,防止死锁
}
}
Environment
- OS (e.g., Linux): WSL2, ubuntu22.04
- FunASR Version (e.g., 1.0.0): main
- Any other relevant information:
- gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
- onnxruntime-linux-x64-1.14.0
- ffmpeg-n5.1.6-9-gdcdfd7fb62-linux64-gpl-shared-5.1
-boost_1_88_0