From a660cfb7ad27479130ff609e853cfeb85071e068 Mon Sep 17 00:00:00 2001 From: Song Date: Wed, 4 Dec 2024 15:09:06 +0800 Subject: [PATCH] fix: avoid deadlock when the server fails to start. --- src/socket.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/socket.cpp b/src/socket.cpp index e9402d3..11f3b70 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -233,17 +233,21 @@ namespace dap { Socket::Socket(const char* address, const char* port) : shared(Shared::create(address, port)) { if (shared) { + bool failed = false; shared->lock([&](SOCKET socket, const addrinfo* info) { if (bind(socket, info->ai_addr, (int)info->ai_addrlen) != 0) { - shared.reset(); + failed = true; return; } if (listen(socket, 0) != 0) { - shared.reset(); + failed = true; return; } }); + if (failed) { + shared.reset(); + } } }