On Wed, 10 Dec 2025 15:45:35 GMT, Alan Bateman <[email protected]> wrote:

>> Hi,
>> 
>> This change updates the use of NET_ThrowNew in Inet4AddressImpl.c + 
>> Inet6AddressImpl.c (unix).
>> Currently EINTR is incorrectly handled in NET_ThrowNew to throw 
>> InterruptedIOException.
>> 
>> The only possible places in these files where EINTR can be returned is in 
>> the sendto() calls
>> for ping4() and ping6() used by the InetAddress.isReachable() API.
>> 
>> The change checks for EINTR returned from those calls and restarts the 
>> sendto()
>> if the timeout allows it. If EINTR is detected by NET_ThrowNew it is thrown 
>> as an ordinary
>> SocketException, but this should not happen.
>> 
>> The fix is only partially tested as it is difficult to make sendto() return 
>> EINTR in practice, but
>> I added a unit test for the new native function that checks if the timeout 
>> has expired.
>> 
>> Thanks,
>> Michael
>
> src/java.base/unix/native/libnet/Inet4AddressImpl.c line 401:
> 
>> 399:         icmp->icmp_cksum = in_cksum((u_short *)icmp, plen);
>> 400:         // send it
>> 401:         while (1) {
> 
> Are you sure it is possible for sendto to block indefinitely here? Maybe 
> EINTR is possible but I think it would be okay to retry unconditionally, 
> meaning I don't think timerMillisExpired is needed here.
> 
> Are you sure that we restart for the other blocking syscalls (poll, recvfrom, 
> ...) in these methods?

Oops. Didn't notice I had left the other calls out. Will add them now.

As for sendto() it's a lot less likely to block and I doubt it can block 
indefinitely, but I imagine it can block if socket buffer is full. I don't have 
a strong preference. If EINTR can be returned maybe it should be handled the 
same way?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/28750#discussion_r2607281100

Reply via email to