Skip to content

Commit

Permalink
socket: fix potential double close (#2663)
Browse files Browse the repository at this point in the history
`_fd` should be reset if `ResetFileDescriptor` is going to return -1,
otherwise the fd will be closed in callers like `CheckConnectedAndKeepWrite`
or `Server::StartInernal` and socket lifecycle methods like `BeforeRecycled`
or `WaitAndReset`.
  • Loading branch information
BusyJay authored Jun 24, 2024
1 parent 2e18318 commit f12bc52
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/brpc/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ int Socket::ResetFileDescriptor(int fd) {
// Make the fd non-blocking.
if (butil::make_non_blocking(fd) != 0) {
PLOG(ERROR) << "Fail to set fd=" << fd << " to non-blocking";
_fd.store(-1, butil::memory_order_release);
return -1;
}
// turn off nagling.
Expand Down

0 comments on commit f12bc52

Please sign in to comment.