Skip to content

Commit bf56658

Browse files
authored
fix: avoid deadlock when the server fails to start.
1 parent c69444e commit bf56658

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/socket.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,20 @@ namespace dap {
233233
Socket::Socket(const char* address, const char* port)
234234
: shared(Shared::create(address, port)) {
235235
if (shared) {
236+
bool failed = false;
236237
shared->lock([&](SOCKET socket, const addrinfo* info) {
237238
if (bind(socket, info->ai_addr, (int)info->ai_addrlen) != 0) {
238-
shared.reset();
239+
failed = true;
239240
return;
240241
}
241242

242243
if (listen(socket, 0) != 0) {
243-
shared.reset();
244+
failed = true;
244245
return;
245246
}
246247
});
248+
if (failed)
249+
shared.reset();
247250
}
248251
}
249252

0 commit comments

Comments
 (0)