[llvm-branch-commits] [llvm] 460556a - [ORC] Shutdown the socket FD before closing it in FDSimpleRemoteEPCTransport (#196835)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu May 28 00:01:02 PDT 2026
Author: Min-Yih Hsu
Date: 2026-05-26T10:28:40-07:00
New Revision: 460556ae66e45b203f49c1c43878b4e0ef6d0f49
URL: https://github.com/llvm/llvm-project/commit/460556ae66e45b203f49c1c43878b4e0ef6d0f49
DIFF: https://github.com/llvm/llvm-project/commit/460556ae66e45b203f49c1c43878b4e0ef6d0f49.diff
LOG: [ORC] Shutdown the socket FD before closing it in FDSimpleRemoteEPCTransport (#196835)
It is totally possible that when
`FDSimpleRemoteEPCTransport::disconnect` is called,
`FDSimpleRemoteEPCTransport::listenLoop` is still reading on the socket
FD the former is closing. On Linux, closing a socket FD when it is being
read by another thread is an undefined behavior I believe. And on modern
kernels, the reading thread will not be waken up, so `listenLoop` will
be blocked forever and preventing the process from exiting.
This patch fixes this issue by calling `shutdown(2)` on the socket FDs
before closing them.
Added:
Modified:
llvm/lib/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.cpp b/llvm/lib/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.cpp
index 08fcd1c45445c..a8bf26d7da033 100644
--- a/llvm/lib/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.cpp
@@ -20,6 +20,9 @@
#else
#include <io.h>
#endif
+#ifndef _WIN32
+#include <sys/socket.h>
+#endif
namespace {
@@ -115,6 +118,13 @@ void FDSimpleRemoteEPCTransport::disconnect() {
Disconnected = true;
bool CloseOutFD = InFD != OutFD;
+#ifndef _WIN32
+ // We need to shutdown the socket to wake up (and terminate) any ongoing
+ // blocking read on this FD. If the FD is not a socket, shutdown will just
+ // complain through errno (instead of crashing).
+ // FIXME: what about Windows?
+ ::shutdown(InFD, CloseOutFD ? SHUT_RD : SHUT_RDWR);
+#endif
// Close InFD.
while (close(InFD) == -1) {
if (errno == EBADF)
@@ -123,6 +133,10 @@ void FDSimpleRemoteEPCTransport::disconnect() {
// Close OutFD.
if (CloseOutFD) {
+#ifndef _WIN32
+ // FIXME: what about Windows?
+ ::shutdown(OutFD, SHUT_WR);
+#endif
while (close(OutFD) == -1) {
if (errno == EBADF)
break;
More information about the llvm-branch-commits
mailing list