From cd97e7b3f125c0c4a5d3a2ae4bc1ea967be56455 Mon Sep 17 00:00:00 2001 From: Artur Mukhamadiev Date: Fri, 11 Sep 2026 17:50:00 +0300 Subject: [PATCH] fix(rpc): stop server before joining threads in crpc_deinit crpc_deinit() called TcpServer::join() without stop(), so with any live TCP client the accept thread never exited and deinit blocked forever on the caller's thread (froze the Unity main thread in OnDestroy during e2e). Call server->stop() first, which clears running_ and unblocks accept, then join. --- src/server_api.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/server_api.cpp b/src/server_api.cpp index 79480bb..4a98d15 100644 --- a/src/server_api.cpp +++ b/src/server_api.cpp @@ -98,8 +98,13 @@ void crpc_init_with_address(const char *ip, int port) { } void crpc_deinit() { - if (server) + if (server) { + // Must stop() before join(): stop() clears running_ so the accept + // thread can exit; join() alone would block forever while a client + // thread is blocked in a read (deadlock observed in Unity e2e). + server->stop(); server->join(); + } server.reset(); std::lock_guard lock(gc_mtx); gc.clear();