socket: fix potential double close (#2663)
`_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`.
diff --git a/src/brpc/socket.cpp b/src/brpc/socket.cpp
index ac1c37a..12230d7 100644
--- a/src/brpc/socket.cpp
+++ b/src/brpc/socket.cpp
@@ -594,6 +594,7 @@
// 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.