Closed tzakharko closed 3 years ago
Thank you for reporting this. I can reproduce this in a vanilla R session:
$ R --vanilla
R version 4.1.0 Patched (2021-06-26 r80566) -- "Camp Pontanezen"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
...
> future::plan(future::multisession, workers = 2)
> dummy <- gc()
Warning message:
In .Internal(gc(verbose, reset, full)) :
closing unused connection 3 (localhost)
> future::plan(future::multisession, workers = 2)
> dummy <- gc()
Warning message:
In .Internal(gc(verbose, reset, full)) :
closing unused connection 3 (localhost)
>
Since 'multisession' uses parallelly::makeClusterPSOCK()
, here's a reproducible example without using the future package:
$ R --vanilla
R version 4.1.0 Patched (2021-06-26 r80566) -- "Camp Pontanezen"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
...
> cl <- parallelly::makeClusterPSOCK(1)
> dummy <- gc()
Warning message:
In .Internal(gc(verbose, reset, full)) :
closing unused connection 3 (localhost)
>
## stdin=0, stdout=1, stderr=2
> getAllConnections()
[1] 0 1 2
> cl <- parallelly::makeClusterPSOCK(1)
> getAllConnections()
[1] 0 1 2 3 4
## the connection to the single worker has index 4
> as.integer(cl[[1]]$con)
[1] 4
## connection with index HenrikBengtsson/future#3 is the stray connect
> dummy <- gc()
Warning message:
In .Internal(gc(verbose, reset, full)) :
closing unused connection 3 (localhost)
FWIW, parallel::makePSOCKcluster(1)
does not have this problem.
This stray connection comes from the new setup_strategy = "parallel"
in parallelly (>= 1.26.0). One way to avoid it, is to use setup_strategy = "sequential"
:
> getAllConnections()
[1] 0 1 2
> cl <- parallelly::makeClusterPSOCK(1, setup_strategy = "sequential")
> getAllConnections()
[1] 0 1 2 3
> dummy <- gc()
>
This can also be set via an option:
options(parallelly.makeNodePSOCK.setup_strategy = "sequential")
or the corresponding environment variable, cf. help("parallelly.options", package="parallelly")
.
This also works with plan(multisession)
;
> future::plan(future::multisession, workers = 2, setup_strategy = "sequential")
> getAllConnections()
[1] 0 1 2 3 4
> dummy <- gc()
>
Since this is a bug in parallelly, I'll transfer this issue over to that repo.
Fixed in the develop version of parallelly, cf. commit 67836def. To install that version, use:
remotes::install_github("HenrikBengtsson/parallelly", ref="develop")
Details: The problem was that the socket connection was indeed set up to be cleaned up automatically when exiting makeClusterPSOCK()
;
However, an older strategy would override this at the very end:
Thanks for the quick fix! Can confirm that the warning is gone. As far as I am concerned, this issue can be closed.
Describe the bug
Using
plan(multisession)
generates warnings about unused connections. This is so at least on macOS with R 4.1.0. I did not have the chance to test other platforms.Reproduce example
Session information