[Rd] R_SocketWaitMultiple(): Thinko leading to negative select() timeouts(?)

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Thu Mar 26 09:34:40 CET 2026


>>>>> Henrik Bengtsson 
>>>>>     on Tue, 24 Mar 2026 20:54:00 -0700 writes:

    > SUMMARY:
    > I think there is a thinko in R_SocketWaitMultiple() that can result in:

    > howmany = R_SelectEx(maxfd+1, &rfd, &wfd, NULL, &tv, NULL);

    > being called with a negative timeout 'tv' (tv.tv_sec and tv.tv_usec
    > negative). I think the bug is that:

    > if (mytimeout < 0 || R_wait_usec / 1e-6 < mytimeout - used)

    > should be:

    > if (mytimeout < 0 || R_wait_usec / 1e6 < mytimeout - used)

or as you say below

     if (mytimeout < 0 || R_wait_usec * 1e-6 < mytimeout - used)

I've committed the latter,  as indeed, in
<R>/src/modules/internet/Rsock.c   microseconds = μ sec --> 'usec"'
are always multiplied by 1e-6 when transformed to  seconds
(well, with one exception where *integer division*
 delta / 1000000  is used).

This "only" affects "Unix" ... it's still interesting that this
has never be seen or noticed as having a negative effect in all
the 23 years that this part of socket code exists...

Thanks a lot, Henrik!

Martin



More information about the R-devel mailing list