Connections left open after terminating a callr background process
wlandau opened this issue · 4 comments
wlandau commented
In a package where I use callr::r_bg(supervise = TRUE)
, R CMD check
shows an error with:
Error: connections left open:
/var/folders/k3/q1f45fsn4_13jbn0742d4zj40000gn/T//RtmpuBZOVi/working_dir/RtmpBl7Qm1/supervisor_stdin157e975c24c10 (fifo)
/var/folders/k3/q1f45fsn4_13jbn0742d4zj40000gn/T//RtmpuBZOVi/working_dir/RtmpBl7Qm1/supervisor_stdout157e9270fead6 (fifo)
Reprex:
packageVersion("processx")
#> [1] '3.5.2.9000'
packageDescription("processx")$GithubSHA1
#> [1] "c1a84e2694463205c4a01fef4075fc02cd3ad530"
packageVersion("callr")
#> [1] '3.7.0.9000'
packageDescription("callr")$GithubSHA1
#> [1] "bb757725fb5d13dcf5065dd1e7ba9a82868d8fcb"
showConnections()
#> description class mode text isopen can read can write
#> 3 "output" "textConnection" "wr" "text" "opened" "no" "yes"
px <- callr::r_bg(fun = function() Sys.sleep(Inf), supervise = TRUE)
while (!px$is_alive()) Sys.sleep(0.1)
showConnections()
#> description
#> 3 "output"
#> 4 "/var/folders/k3/q1f45fsn4_13jbn0742d4zj40000gn/T//Rtmp6MzHeC/supervisor_stdin180fc23269a5d"
#> 5 "/var/folders/k3/q1f45fsn4_13jbn0742d4zj40000gn/T//Rtmp6MzHeC/supervisor_stdout180fc3b6061b2"
#> class mode text isopen can read can write
#> 3 "textConnection" "wr" "text" "opened" "no" "yes"
#> 4 "fifo" "w+" "text" "opened" "yes" "yes"
#> 5 "fifo" "w+" "text" "opened" "yes" "yes"
px$kill(close_connections = TRUE)
#> [1] TRUE
while (px$is_alive()) Sys.sleep(0.1)
showConnections() # Should not show supervisor temp files.
#> description
#> 3 "output"
#> 4 "/var/folders/k3/q1f45fsn4_13jbn0742d4zj40000gn/T//Rtmp6MzHeC/supervisor_stdin180fc23269a5d"
#> 5 "/var/folders/k3/q1f45fsn4_13jbn0742d4zj40000gn/T//Rtmp6MzHeC/supervisor_stdout180fc3b6061b2"
#> class mode text isopen can read can write
#> 3 "textConnection" "wr" "text" "opened" "no" "yes"
#> 4 "fifo" "w+" "text" "opened" "yes" "yes"
#> 5 "fifo" "w+" "text" "opened" "yes" "yes"
Created on 2022-02-06 by the reprex package (v2.0.1)
Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.1.2 (2021-11-01)
#> os macOS Big Sur 10.16
#> system x86_64, darwin17.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz America/Indiana/Indianapolis
#> date 2022-02-06
#> pandoc 2.11.4 @ /Applications/RStudio.app/Contents/MacOS/pandoc/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> backports 1.4.1 2021-12-13 [1] CRAN (R 4.1.0)
#> callr 3.7.0.9000 2022-02-06 [1] Github (r-lib/callr@bb75772)
#> cli 3.1.1 2022-01-20 [1] CRAN (R 4.1.2)
#> crayon 1.4.2 2021-10-29 [2] CRAN (R 4.1.0)
#> digest 0.6.29 2021-12-01 [1] CRAN (R 4.1.0)
#> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.1.0)
#> evaluate 0.14 2019-05-28 [2] CRAN (R 4.1.0)
#> fansi 1.0.2 2022-01-14 [1] CRAN (R 4.1.2)
#> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.1.0)
#> fs 1.5.2 2021-12-08 [2] CRAN (R 4.1.0)
#> glue 1.6.1 2022-01-22 [1] CRAN (R 4.1.2)
#> highr 0.9 2021-04-16 [2] CRAN (R 4.1.0)
#> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.1.0)
#> knitr 1.37 2021-12-16 [1] CRAN (R 4.1.0)
#> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.0)
#> magrittr 2.0.2 2022-01-26 [2] CRAN (R 4.1.2)
#> pillar 1.6.5 2022-01-25 [1] CRAN (R 4.1.0)
#> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.1.0)
#> processx 3.5.2.9000 2022-02-06 [1] Github (r-lib/processx@c1a84e2)
#> ps 1.6.0 2021-02-28 [2] CRAN (R 4.1.0)
#> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.1.0)
#> R.cache 0.15.0 2021-04-30 [2] CRAN (R 4.1.0)
#> R.methodsS3 1.8.1 2020-08-26 [2] CRAN (R 4.1.0)
#> R.oo 1.24.0 2020-08-26 [2] CRAN (R 4.1.0)
#> R.utils 2.11.0 2021-09-26 [2] CRAN (R 4.1.0)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.0)
#> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.0)
#> rlang 1.0.0 2022-01-26 [1] CRAN (R 4.1.2)
#> rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.0)
#> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.1.0)
#> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.1.0)
#> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.1.0)
#> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.1.0)
#> styler 1.6.2 2021-09-23 [2] CRAN (R 4.1.0)
#> tibble 3.1.6 2021-11-07 [1] CRAN (R 4.1.0)
#> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.0)
#> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.0)
#> withr 2.4.3 2021-11-30 [2] CRAN (R 4.1.0)
#> xfun 0.29 2021-12-14 [1] CRAN (R 4.1.0)
#> yaml 2.2.2 2022-01-25 [2] CRAN (R 4.1.0)
#>
#> [1] /Users/c240390/Library/R/x86_64/4.1/library
#> [2] /Library/Frameworks/R.framework/Versions/4.1/Resources/library
#>
#> ──────────────────────────────────────────────────────────────────────────────
gaborcsardi commented
This is not a bug. The supervisor uses connections, apparently. If you want to close them, then kill the supervisor at the end of your test cases.
wlandau commented
Got it. How do I close the supervisor of a callr
process?
gaborcsardi commented
processx::supervisor_kill()
wlandau commented
Seems to have worked, thanks.