You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
parallel::clusterEvalQ(cl, Sys.sleep(1.0)) stalls on WSL2 #826
It first spawns some R-session instances, but then hangs and does not finish the job. It falls back to a single process with little CPU utilization, but does not finish. After esc/CTRL-C I get:
Warning: Caught FutureInterruptError. Canceling all iterations ...
Error: future_lapply() interrupted at 2026-03-01T10:36:49, while running on ‘25-11427’ (pid 195644)
Yes, plan(multisession, workers = 2) works for me as well.
If I use the default plan(multisession) as used in some of the examples, it consistently hangs for me.
That's very useful information. How many CPU cores does your WSL2 system have/see, e.g. what does the following report?
>parallelly::availableCores(which="all")
One hypothesis now is that it's over-parallelizing, but still, that should not cause it to freeze.
Looking at your sessionInfo(), I noticed a few things:
It does not reflect the code you ran, e.g. it's missing future.apply and it lists many other packages not used, e.g. foreach and doParallel.
You're using an outdated version of future - I don't think it matters, but just in case, could you please make sure to update all your packages.
It lists rstudioapi, which suggests your running this in the RStudio Console. To rule out RStudio here, could you please retry with plan(multisession) running R directly from the terminal (not the RStudio GUI)?
You're saying "doparallel works on WSL2", but it's not clear to me exactly how you set it up and with how many workers. doParallel is actually providing two completely different types on parallel workers. Knowing the details will help narrow in on the cause - I suspect your problem can be reproduced with vanilla parallel code, but hard to tell right now.
PS. Please try to update your R packages - it helps to rule out stuff.
I see. It's really hard for me to help out any further here, if I don't fully understand your set up (e.g. if you use RStudio or vanilla R, if your packages are up-to-date, and exactly how you use registerDoParallel()). Seeing exact code is more or less essential.
There's also plan(future.mirai::mirai_multisession) and plan(future.callr::callr) to try and see if the problem is there too, or specific to the multisession backend. Knowing will rule out a lot of things.
One can also see if it can be reproduced without futurize (which I doubt matters here) and future.apply (which I give a slight probability to be involved) and see if it is happens with just future, e.g.
I think the issue is that setting up the session gets stuck. I get:
$ R --vanilla
R version 4.5.2 (2025-10-31) -- "[Not] Part in a Rumble"
Copyright (C) 2025 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(future)
plan(multisession)
futureSessionInfo()
*** Package versions
future 1.69.0, parallelly 1.46.1, parallel 4.5.2, globals 0.19.0, listenv 0.10.0
*** Allocations
availableCores():
system /proc/self/status nproc
14 14 14
availableWorkers():
$nproc
[1] "localhost" "localhost" "localhost" "localhost" "localhost" "localhost"
[7] "localhost" "localhost" "localhost" "localhost" "localhost" "localhost"
[13] "localhost" "localhost"
$system
[1] "localhost" "localhost" "localhost" "localhost" "localhost" "localhost"
[7] "localhost" "localhost" "localhost" "localhost" "localhost" "localhost"
[13] "localhost" "localhost"
*** Settings
- future.plan=<not set>
- future.fork.multithreading.enable=<not set>
- future.globals.maxSize=<not set>
- future.globals.onReference=<not set>
- future.resolve.recursive=<not set>
- future.rng.onMisuse=<not set>
- future.wait.timeout=<not set>
- future.wait.interval=<not set>
- future.wait.alpha=<not set>
- future.startup.script=<not set>
*** Backends
Number of workers: 14
List of future strategies:
1. multisession:
- args: function (..., workers = availableCores(constraints = "connections-16"), rscript_libs = .libPaths())
- tweaked: FALSE
- call: plan(multisession)
*** Basic tests
Main R session details:
pid r sysname release
1 23931 4.5.2 Linux 6.6.87.2-microsoft-standard-WSL2
version nodename machine login
1 futureverse/futurize#1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 host001 x86_64 user002
user effective_user
1 user001 user001
It stops right there and does not report the other nodes. I waited for more than a minute.
It works reliably with 2 or 4 workers and sometimes with 6.
> library(future)
plan(multisession, workers = 4)
futureSessionInfo()
*** Package versions
future 1.69.0, parallelly 1.46.1, parallel 4.5.2, globals 0.19.0, listenv 0.10.0
*** Allocations
availableCores():
system /proc/self/status nproc
14 14 14
availableWorkers():
$nproc
[1] "localhost" "localhost" "localhost" "localhost" "localhost" "localhost"
[7] "localhost" "localhost" "localhost" "localhost" "localhost" "localhost"
[13] "localhost" "localhost"
$system
[1] "localhost" "localhost" "localhost" "localhost" "localhost" "localhost"
[7] "localhost" "localhost" "localhost" "localhost" "localhost" "localhost"
[13] "localhost" "localhost"
*** Settings
- future.plan=<not set>
- future.fork.multithreading.enable=<not set>
- future.globals.maxSize=<not set>
- future.globals.onReference=<not set>
- future.resolve.recursive=<not set>
- future.rng.onMisuse=<not set>
- future.wait.timeout=<not set>
- future.wait.interval=<not set>
- future.wait.alpha=<not set>
- future.startup.script=<not set>
*** Backends
Number of workers: 4
List of future strategies:
1. multisession:
- args: function (..., workers = 4)
- tweaked: TRUE
- call: plan(multisession, workers = 4)
*** Basic tests
Main R session details:
pid r sysname release
1 28373 4.5.2 Linux 6.6.87.2-microsoft-standard-WSL2
version nodename machine login
1 futureverse/futurize#1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 host001 x86_64 user002
user effective_user
1 user001 user001
Worker R session details:
worker pid r sysname release
1 1 28441 4.5.2 Linux 6.6.87.2-microsoft-standard-WSL2
2 2 28440 4.5.2 Linux 6.6.87.2-microsoft-standard-WSL2
3 3 28442 4.5.2 Linux 6.6.87.2-microsoft-standard-WSL2
4 4 28443 4.5.2 Linux 6.6.87.2-microsoft-standard-WSL2
version nodename machine login
1 futureverse/futurize#1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 host001 x86_64 user002
2 futureverse/futurize#1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 host001 x86_64 user002
3 futureverse/futurize#1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 host001 x86_64 user002
4 futureverse/futurize#1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 host001 x86_64 user002
user effective_user
1 user001 user001
2 user001 user001
3 user001 user001
4 user001 user001
Number of unique worker PIDs: 4 (as expected)
Anything more, and it gets stuck. Maybe a weird interaction between the Windows host and the Ubuntu WSL2 instance?
Thanks. This is all very helpful and definitely a big step forward.
plan(multisession) uses a PSOCK cluster of the parallel package. Such clusters rely on socket connections for the main R process to communicate with the parallel workers. Given that plan(future.callr::callr) and plan(multicore) work, it could be that there is something conflicting the R connections (e.g. firewall rules, but shouldn't happen under Linux WSL2).
We've now excluded both futurize and future.apply from the equation (and RStudio). I suspect that this is also independent of the future package, but before we can rule that out, the next thing to test would be:
library(future)
cl<-parallel::makeCluster(14) ## Set up 14 vanilla PSOCK cluster workers
print(cl)
plan(cluster, workers=cl)
futureSessionInfo()
What is the output and does that also freeze? If not, what about:
library(future)
cl<-parallel::makeCluster(14, type=parallelly::RPSOCK) ## Set up 14 "enhanced" PSOCK cluster workers
print(cl)
plan(cluster, workers=cl)
futureSessionInfo()
both freeze. Using parallel directly (clusterApply) works as expected:
cl <- parallel::makeCluster(14)
fs <- parallel::clusterApply(cl, seq_along(cl), function(ii) {
data.frame(worker = ii, pid = Sys.getpid(), r = getRversion(), as.list(Sys.info()))
})
vs <- value(fs)
str(vs)
However, if I add a Sys.sleep() to the parallelized function, the processes never seem to wake up, and it hangs. Looks like there is an issue with how nanosleep() interacts in WSL2.
Hi, I was traveling and had no time to look into this. I wonder if it is related to a weird WSL2 setup that my university uses. I think we need to see if someone with a vanilla installation of Windows/WSL2 has the same issues.
Yes, maybe. But if you could try what I wrote in my last comment, then we can narrow in on the problem further, which then simplifies asking others in your organization to check what they get. So, first goal is to identify a minimal reproducible example.
Activity
HenrikBengtsson commentedon Mar 2, 2026
Thanks for bringing this over here. I completely missed this issue when I continued our thread over at mhahsler/TSP#22 (comment):
You also wrote (mhahsler/TSP#22 (comment)):
That's very useful information. How many CPU cores does your WSL2 system have/see, e.g. what does the following report?
One hypothesis now is that it's over-parallelizing, but still, that should not cause it to freeze.
Looking at your
sessionInfo(), I noticed a few things:It does not reflect the code you ran, e.g. it's missing
future.applyand it lists many other packages not used, e.g.foreachanddoParallel.You're using an outdated version of
future- I don't think it matters, but just in case, could you please make sure to update all your packages.It lists
rstudioapi, which suggests your running this in the RStudio Console. To rule out RStudio here, could you please retry withplan(multisession)running R directly from the terminal (not the RStudio GUI)?mhahsler commentedon Mar 2, 2026
When I use
Then it hangs as well. It seems to work fine up to 8 workers.
HenrikBengtsson commentedon Mar 2, 2026
Informative, but really odd. Did you run this in RStudio or from the terminal?
FYI,
plan(multisession)is basically equivalent to:which is nearly the same as:
The corresponding doParallel setup would be:
You're saying "doparallel works on WSL2", but it's not clear to me exactly how you set it up and with how many workers. doParallel is actually providing two completely different types on parallel workers. Knowing the details will help narrow in on the cause - I suspect your problem can be reproduced with vanilla parallel code, but hard to tell right now.
PS. Please try to update your R packages - it helps to rule out stuff.
mhahsler commentedon Mar 3, 2026
I tried it using both. I wonder if it is some configuration issue on my machine only.
HenrikBengtsson commentedon Mar 3, 2026
I see. It's really hard for me to help out any further here, if I don't fully understand your set up (e.g. if you use RStudio or vanilla R, if your packages are up-to-date, and exactly how you use
registerDoParallel()). Seeing exact code is more or less essential.Another thing to try is with forked workers, e.g.
There's also
plan(future.mirai::mirai_multisession)andplan(future.callr::callr)to try and see if the problem is there too, or specific to themultisessionbackend. Knowing will rule out a lot of things.One can also see if it can be reproduced without futurize (which I doubt matters here) and future.apply (which I give a slight probability to be involved) and see if it is happens with just future, e.g.
mhahsler commentedon Mar 3, 2026
I think the issue is that setting up the session gets stuck. I get:
It stops right there and does not report the other nodes. I waited for more than a minute.
It works reliably with 2 or 4 workers and sometimes with 6.
Anything more, and it gets stuck. Maybe a weird interaction between the Windows host and the Ubuntu WSL2 instance?
-Michael
mhahsler commentedon Mar 3, 2026
Btw:
plan(future.callr::callr)andplan(multicore)work and create 14 workers.HenrikBengtsson commentedon Mar 3, 2026
Thanks. This is all very helpful and definitely a big step forward.
plan(multisession)uses a PSOCK cluster of the parallel package. Such clusters rely on socket connections for the main R process to communicate with the parallel workers. Given thatplan(future.callr::callr)andplan(multicore)work, it could be that there is something conflicting the R connections (e.g. firewall rules, but shouldn't happen under Linux WSL2).We've now excluded both futurize and future.apply from the equation (and RStudio). I suspect that this is also independent of the future package, but before we can rule that out, the next thing to test would be:
What is the output and does that also freeze? If not, what about:
mhahsler commentedon Mar 4, 2026
Both versions freeze when I request more than 2 workers. It looks like the connections are open.
but then
futureSessionInfo()hangs.HenrikBengtsson commentedon Mar 4, 2026
Perfect. To peel off more, next would be to see if we can reproduce it with manually created futures; does the following also hang?
If so, what about:
?
mhahsler commentedon Mar 4, 2026
both freeze. Using parallel directly (clusterApply) works as expected:
However, if I add a
Sys.sleep()to theparallelizedfunction, the processes never seem to wake up, and it hangs. Looks like there is an issue with hownanosleep()interacts in WSL2.HenrikBengtsson commentedon Mar 4, 2026
Wow, interesting. There might be a bug in R here around how
Sys.sleep()is implemented. Let's see.To rule out more things, does the following also freeze on you?
PS. You don't need
vs <- value(fs)here or in your latest example - that's only for futures.If that freezes, what about
?
BTW, what you found means that your original
ys <- lapply(xs, slow_fcn) |> futurize()should work if you dropSys.sleep()call - is that the case?HenrikBengtsson commentedon Mar 18, 2026
Hello, I haven't heard back from you here. Did you resolve this?
mhahsler commentedon Mar 22, 2026
Hi, I was traveling and had no time to look into this. I wonder if it is related to a weird WSL2 setup that my university uses. I think we need to see if someone with a vanilla installation of Windows/WSL2 has the same issues.
HenrikBengtsson commentedon Mar 22, 2026
Yes, maybe. But if you could try what I wrote in my last comment, then we can narrow in on the problem further, which then simplifies asking others in your organization to check what they get. So, first goal is to identify a minimal reproducible example.
mhahsler commentedon Mar 23, 2026
and
hang. If I set the sleep to < .4, then they both return after exactly the set time.
without the sleep works.
[-]Issue with futurize on WSL2[/-][+]parallel::clusterEvalQ(cl, Sys.sleep(1.0)) stalls on WSL2[/+]