Repository navigation
Conversation
| @@ -418,7 +418,9 @@ JNIEXPORT jint JNICALL Java_org_newsclub_net_unix_NativeUnixSocket_poll | |||
| #if defined(_WIN32) | |||
| ret = WSAPoll(pollFd, nfds, timeout); | |||
There was a problem hiding this comment.
why is Windows excluded from this logic?
There was a problem hiding this comment.
This change addresses POSIX poll() returning EINTR. WSAPoll does not appear to document an equivalent interruption error (and I did use some AI to search through and I couldn't find an equivalent either). If there is an equivalent Windows case that should have the same behavior, I’m open to handling it here as well.
| #else | ||
| ret = poll(pollFd, nfds, timeout); | ||
| do { | ||
| ret = poll(pollFd, nfds, timeout); |
There was a problem hiding this comment.
timeout would need to be reduced by the time already elapsed since the first call, otherwise we may be polling for too long
There was a problem hiding this comment.
Good call, I'll update the PR reducing timeout when retrying.
There was a problem hiding this comment.
Fixed in d2d8022. Finite polls now use a monotonic deadline and pass only the remaining time after EINTR, so retries cannot extend the original timeout.
|
@jattisha Thanks for the PR! To clarify, did you ever observe |
|
Also, while I agree that throwing a plain |
I have not personally reproduced it without the interposer. The issue was motivated by a failure observed while profiler signals were being delivered, and I used the interposer to reproduce the same native return condition deterministically. I can look into a test setup.
My concern is that |
Track a monotonic deadline so retries cannot extend finite polls. Add an opt-in native test that interrupts poll with a real POSIX signal and verifies the original deadline is retained.
|
I added the non-interposed test setup in d2d8022. It delivers a real |
|
My AI agent just went a bit above and beyond here, lol. Feel free to push back if anything here is too complex. |
Summary
Retry the POSIX
poll()call when it fails withEINTR.NativeUnixSocket.pollcurrently converts an interrupted system call into aSocketException. A signal delivered while the native call is blocked can therefore surface asjava.net.SocketException: Interrupted system call, even thoughEINTRis transient and the operation can be retried. This is particularly visible when socket I/O is coordinated through the virtual-thread poller.This applies the same established
EINTRretry pattern already used byaccept,connect,receive, andsend.Testing
poll()call originating fromlibjunixsocket-nativereturn-1witherrno = EINTRexactly once.java.net.SocketException: Interrupted system callfromNativeUnixSocket.poll.EINTRwas retried andNativeUnixSocket.pollreturned normally.VirtualThreadPollerTest: 4 tests passed with no failures or skips.git diff --checksuccessfully.