You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[coro_io] dead lock when call server::stop() in server self's thread #905
#include <ylt/coro_rpc/coro_rpc_server.hpp>
#include "rpc_service.h"
using namespace coro_rpc;
using namespace async_simple;
using namespace async_simple::coro;
int main() {
// init rpc server
coro_rpc_server server(/*thread=*/std::thread::hardware_concurrency(),
/*port=*/8801);
coro_rpc_server server2{/*thread=*/1, /*port=*/8802};
// regist normal function for rpc
server.register_handler<echo, async_echo_by_coroutine, async_echo_by_callback,
echo_with_attachment, nested_echo,
return_error_by_context, return_error_by_exception,
rpc_with_state_by_tag, get_ctx_info,
rpc_with_complete_handler, add>();
// regist member function for rpc
HelloService hello_service;
server.register_handler<&HelloService::hello>(&hello_service);
server2.register_handler<echo>();
// async start server
auto res = server2.async_start();
assert(!res.hasResult());
// sync start server & sync await server stop
return !server.start();
}
启动以后程序会一直阻塞,那么如何正常关闭程序呢,如果直接停掉程序可能无法正常调用main函数里面的变量的析构函数,我尝试在一个rpc调用函数中调用server.stop()或者在set_complete_handler里面调用server.stop()都无法正常关闭,请问还有其他方法吗? coro_rpc_server will quit之后还是无法退出
changed the title [-][coro_io] dead lock when call stop() in io_context_pool's thread[/-][+][coro_io] dead lock when call server::stop() in server self's thread[/+]on Feb 14, 2025
Activity
poor-circle commentedon Feb 14, 2025
好吧,在rpc函数直接调用server.stop()似乎会导致死锁,原因是没检查stop请求是否在rpc线程池中发起。目前你可以把stop扔给另外一个线程完成。
poor-circle commentedon Feb 14, 2025
死锁原因:
rpc函数->调用stop请求停止服务->等待当前的rpc函数执行完成->当前rpc函数正在执行stop
HEUBITLYJ commentedon Feb 14, 2025
[-]coro_rpc如何在服务端正常关闭server退出程序[/-][+][coro_io] dead lock when call stop() in io_context_pool's thread[/+]poor-circle commentedon Feb 14, 2025
后续会看下怎么修复,目前你可以抛到另外一个线程去stop
[-][coro_io] dead lock when call stop() in io_context_pool's thread[/-][+][coro_io] dead lock when call server::stop() in server self's thread[/+]HEUBITLYJ commentedon Feb 14, 2025
我在rpc函数中创建了另一个线程sleep 5s后调用stop函数,start函数返回了operation canceled,是否正常
poor-circle commentedon Feb 14, 2025
正常,服务器被用户停止,start()预期的返回值就应该是operation canceled。不就是因为应用程序请求所以中止IO操作了嘛