FunASR icon indicating copy to clipboard operation
FunASR copied to clipboard

c++的http版本,异步返回客户端数据函数无法被正常执行,连接无法被释放,几次请求后就无法再接收新的请求

Open nianjiuhuiyi opened this issue 5 months ago • 2 comments

🐛 Bug

To Reproduce

Steps to reproduce the behavior (always include the command you ran):

  1. 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
  2. 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

nianjiuhuiyi avatar Jun 20 '25 09:06 nianjiuhuiyi

ubuntu24.04 也存在同样的问题 ./funasr-http-server 参数 io-thread-num 默认是 8 执行 curl -F "file=@asr_example_zh.wav" http://127.0.0.1:8000 执行到第 9 次一定会卡死。

dongdongk avatar Jun 24 '25 03:06 dongdongk

ubuntu24.04 也存在同样的问题 ./funasr-http-server 参数 io-thread-num 默认是 8 执行 curl -F "file=@asr_example_zh.wav" http://127.0.0.1:8000 执行到第 9 次一定会卡死。

您好,请问你的这个问题解决了吗,我也出现了这样的问题,能不能参考您的解决方案?

librety123z avatar Oct 27 '25 03:10 librety123z