Skip to content

Commit a660cfb

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

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/socket.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,21 @@ 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();
250+
}
247251
}
248252
}
249253

0 commit comments

Comments
 (0)