[Rd] R_SocketWaitMultiple(): Thinko leading to negative select() timeouts(?)
Peter Dalgaard
pd@|gd @end|ng |rom gm@||@com
Thu Mar 26 13:24:33 CET 2026
Well, we have had mysterious stalls.... E.g. the popup for the CRAN mirror selection can be quite slow on Mac, and given the low reproducibility and difficulty in catching the problem in the act, the cause can go undetected for ages (not saying that this is actually caused by R_SocketWaitMultiple() of course.)
-pd
> On 26 Mar 2026, at 09.34, Martin Maechler <maechler using stat.math.ethz.ch> wrote:
>
>>>>>> 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
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes using cbs.dk Priv: PDalgd using gmail.com
More information about the R-devel
mailing list