Skip to content

Commit

Permalink
fix: avoid deadlock when the server fails to start.
Browse files Browse the repository at this point in the history
  • Loading branch information
sssooonnnggg committed Feb 6, 2025
1 parent c69444e commit a660cfb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

Expand Down

0 comments on commit a660cfb

Please sign in to comment.