[llvm] [LLVM][Cygwin] add workaround for blocking connect/accept (PR #140353)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 16 22:04:33 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: None (jeremyd2019)
<details>
<summary>Changes</summary>
On Cygwin, UNIX sockets involve a handshake between connect and accept to enable SO_PEERCRED/getpeereid handling. This necessitates accept being called before connect can return, but at least the tests in llvm/unittests/Support/raw_socket_stream_test do both on the same thread (first connect and then accept), resulting in a deadlock. Add a call to both places sockets are created that turns off the handshake (and SO_PEERCRED/getpeereid support).
---
Full diff: https://github.com/llvm/llvm-project/pull/140353.diff
1 Files Affected:
- (modified) llvm/lib/Support/raw_socket_stream.cpp (+18)
``````````diff
diff --git a/llvm/lib/Support/raw_socket_stream.cpp b/llvm/lib/Support/raw_socket_stream.cpp
index 7a4be5759f900..fd1c681672138 100644
--- a/llvm/lib/Support/raw_socket_stream.cpp
+++ b/llvm/lib/Support/raw_socket_stream.cpp
@@ -81,6 +81,15 @@ static Expected<int> getSocketFD(StringRef SocketPath) {
"Create socket failed");
}
+#ifdef __CYGWIN__
+ // On Cygwin, UNIX sockets involve a handshake between connect and accept
+ // to enable SO_PEERCRED/getpeereid handling. This necessitates accept being
+ // called before connect can return, but at least the tests in
+ // llvm/unittests/Support/raw_socket_stream_test do both on the same thread
+ // (first connect and then accept), resulting in a deadlock. This call turns
+ // off the handshake (and SO_PEERCRED/getpeereid support).
+ setsockopt(Socket, SOL_SOCKET, SO_PEERCRED, NULL, 0);
+#endif
struct sockaddr_un Addr = setSocketAddr(SocketPath);
if (::connect(Socket, (struct sockaddr *)&Addr, sizeof(Addr)) == -1)
return llvm::make_error<StringError>(getLastSocketErrorCode(),
@@ -147,6 +156,15 @@ Expected<ListeningSocket> ListeningSocket::createUnix(StringRef SocketPath,
return llvm::make_error<StringError>(getLastSocketErrorCode(),
"socket create failed");
+#ifdef __CYGWIN__
+ // On Cygwin, UNIX sockets involve a handshake between connect and accept
+ // to enable SO_PEERCRED/getpeereid handling. This necessitates accept being
+ // called before connect can return, but at least the tests in
+ // llvm/unittests/Support/raw_socket_stream_test do both on the same thread
+ // (first connect and then accept), resulting in a deadlock. This call turns
+ // off the handshake (and SO_PEERCRED/getpeereid support).
+ setsockopt(Socket, SOL_SOCKET, SO_PEERCRED, NULL, 0);
+#endif
struct sockaddr_un Addr = setSocketAddr(SocketPath);
if (::bind(Socket, (struct sockaddr *)&Addr, sizeof(Addr)) == -1) {
// Grab error code from call to ::bind before calling ::close
``````````
</details>
https://github.com/llvm/llvm-project/pull/140353
More information about the llvm-commits
mailing list