Skip to content

Commit b88704d

Browse files
Retry poll() on EINTR when waiting for a socket
A signal delivered to the thread interrupts poll() with EINTR. natsSock_WaitReady treated it as a socket error, so a connection attempt made by an application with a sampling profiler (which sends a signal to every thread) failed spuriously with "poll error: 4". Wait again for whatever is left of the deadline instead. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent cb4edba commit b88704d

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

‎src/unix/sock.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,18 @@ natsSock_WaitReady(int waitMode, natsSockCtx *ctx)
4848
abort();
4949
}
5050

51-
if (deadline != NULL)
52-
timeout = natsDeadline_GetTimeout(deadline);
51+
do
52+
{
53+
if (deadline != NULL)
54+
timeout = natsDeadline_GetTimeout(deadline);
55+
56+
res = poll(&pfd, 1, timeout);
57+
}
58+
// A signal delivered to the thread (e.g. the sampling profiler of the host
59+
// application) interrupts poll() with EINTR. That is not a socket error:
60+
// wait again for whatever is left of the deadline.
61+
while ((res == NATS_SOCK_ERROR) && (NATS_SOCK_GET_ERROR == EINTR));
5362

54-
res = poll(&pfd, 1, timeout);
5563
if (res == NATS_SOCK_ERROR)
5664
return nats_setError(NATS_IO_ERROR, "poll error: %d", NATS_SOCK_GET_ERROR);
5765
else if (res == 0)

0 commit comments

Comments
 (0)