Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

later breaks socket wait (and future package) #4

Closed
jcheng5 opened this issue Aug 3, 2017 · 0 comments
Closed

later breaks socket wait (and future package) #4

jcheng5 opened this issue Aug 3, 2017 · 0 comments

Comments

@jcheng5
Copy link
Member

jcheng5 commented Aug 3, 2017

There's an incompatibility between later and this piece of code in R_SocketWait:

https://github.com/wch/r-source/blob/f2a17ffe009aeeee3f2ee769a6114051a2a6678a/src/modules/internet/Rsock.c#L268-L275

My understanding of this code is that this code is intended to detect "false positives" in the R_SelectEx that occurs a few lines above; R_SocketWait only cares about its socket being ready to read or write, but if R_SelectEx will also return because other, unrelated, input handlers are ready. If this condition is detected, R_SocketWait executes a single input handler and then begins the loop again, reasonably assuming that executing the handler will cause its file descriptor to go cold.

The input handler installed by later doesn't go cold in many cases, it stays hot until R code stops executing. This means that R_SocketWait will never return, and since it was R code that is indirectly calling R_SocketWait, later's file descriptor will never go cold. So we effectively have deadlock (although interrupting R does work fine).

This is a simple repro case:

library(future)
library(magrittr)
plan(multisession)
later::later(~cat("done\n"), 10)
future({Sys.sleep(2);10}) %>% value()

The expected behavior is that [1] 10 is printed at the console after 2 seconds, then the console prompt returns, then done is printed after 10 seconds.

@jcheng5 jcheng5 closed this as completed in 65d21d6 Aug 3, 2017
jcheng5 added a commit that referenced this issue Aug 3, 2017
Fix issue #4: later breaks socket wait (and `future` package)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant