vroom icon indicating copy to clipboard operation
vroom copied to clipboard

`vroom` does not close failed connections

Open mrcaseb opened this issue 2 years ago • 0 comments

This is more or less the same issue as in https://github.com/tidyverse/readr/issues/1050

vroom doesn't close connections that failed, e.g. a URL with a typo.

# Correct URL
to_load <- "https://cloud.r-project.org/CRAN_mirrors.csv"
mirrors <- vroom::vroom(to_load, show_col_types = FALSE)
showConnections(all = TRUE)
#>   description class            mode text   isopen   can read can write
#> 0 "stdin"     "terminal"       "r"  "text" "opened" "yes"    "no"     
#> 1 "stdout"    "terminal"       "w"  "text" "opened" "no"     "yes"    
#> 2 "stderr"    "terminal"       "w"  "text" "opened" "no"     "yes"    
#> 3 "output"    "textConnection" "wr" "text" "opened" "no"     "yes"

# URL with typo
to_load_typo <- "https://cloud.r-project.org/CRAN_mirrorsZ.csv"
mirrors <- vroom::vroom(to_load_typo, show_col_types = FALSE)
#> Error in open.connection(structure(4L, class = c("curl", "connection"), conn_id = <pointer: 0x153>), : HTTP error 404.
showConnections(all = TRUE)
#>   description                                     class            mode text  
#> 0 "stdin"                                         "terminal"       "r"  "text"
#> 1 "stdout"                                        "terminal"       "w"  "text"
#> 2 "stderr"                                        "terminal"       "w"  "text"
#> 3 "output"                                        "textConnection" "wr" "text"
#> 4 "https://cloud.r-project.org/CRAN_mirrorsZ.csv" "curl"           "rb" "text"
#>   isopen   can read can write
#> 0 "opened" "yes"    "no"     
#> 1 "opened" "no"     "yes"    
#> 2 "opened" "no"     "yes"    
#> 3 "opened" "no"     "yes"    
#> 4 "closed" "yes"    "no"

Created on 2023-02-19 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.1 (2022-06-23)
#>  os       macOS Ventura 13.1
#>  system   aarch64, darwin20
#>  ui       X11
#>  language en
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Europe/Berlin
#>  date     2023-02-19
#>  pandoc   2.19.2 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date (UTC) lib source
#>  bit           4.0.5      2022-11-15 [1] CRAN (R 4.2.0)
#>  bit64         4.0.5      2020-08-30 [1] CRAN (R 4.2.0)
#>  cli           3.6.0      2023-01-09 [1] CRAN (R 4.2.0)
#>  crayon        1.5.2      2022-09-29 [1] CRAN (R 4.2.0)
#>  curl          5.0.0      2023-01-12 [1] CRAN (R 4.2.0)
#>  digest        0.6.31     2022-12-11 [1] CRAN (R 4.2.0)
#>  evaluate      0.20       2023-01-17 [1] CRAN (R 4.2.0)
#>  fansi         1.0.4      2023-01-22 [1] CRAN (R 4.2.0)
#>  fastmap       1.1.0      2021-01-25 [1] CRAN (R 4.2.0)
#>  fs            1.6.1      2023-02-06 [1] CRAN (R 4.2.0)
#>  glue          1.6.2      2022-02-24 [1] CRAN (R 4.2.0)
#>  htmltools     0.5.4      2022-12-07 [1] CRAN (R 4.2.0)
#>  knitr         1.42       2023-01-25 [1] CRAN (R 4.2.0)
#>  lifecycle     1.0.3      2022-10-07 [1] CRAN (R 4.2.0)
#>  magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.2.0)
#>  pillar        1.8.1      2022-08-19 [1] CRAN (R 4.2.0)
#>  pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.2.0)
#>  purrr         1.0.1      2023-01-10 [1] CRAN (R 4.2.0)
#>  R.cache       0.16.0     2022-07-21 [1] CRAN (R 4.2.0)
#>  R.methodsS3   1.8.2      2022-06-13 [1] CRAN (R 4.2.0)
#>  R.oo          1.25.0     2022-06-12 [1] CRAN (R 4.2.0)
#>  R.utils       2.12.2     2022-11-11 [1] CRAN (R 4.2.0)
#>  reprex        2.0.2      2022-08-17 [1] CRAN (R 4.2.0)
#>  rlang         1.0.6      2022-09-24 [1] CRAN (R 4.2.0)
#>  rmarkdown     2.20       2023-01-19 [1] CRAN (R 4.2.0)
#>  rstudioapi    0.14       2022-08-22 [1] CRAN (R 4.2.0)
#>  sessioninfo   1.2.2      2021-12-06 [1] CRAN (R 4.2.0)
#>  styler        1.9.0      2023-01-15 [1] CRAN (R 4.2.0)
#>  tibble        3.1.8      2022-07-22 [1] CRAN (R 4.2.0)
#>  tidyselect    1.2.0.9000 2022-11-02 [1] Github (tidyverse/tidyselect@b449033)
#>  tzdb          0.3.0      2022-03-28 [1] CRAN (R 4.2.0)
#>  utf8          1.2.3      2023-01-31 [1] CRAN (R 4.2.0)
#>  vctrs         0.5.2      2023-01-23 [1] CRAN (R 4.2.0)
#>  vroom         1.6.1      2023-01-22 [1] CRAN (R 4.2.0)
#>  withr         2.5.0      2022-03-03 [1] CRAN (R 4.2.0)
#>  xfun          0.37       2023-01-31 [1] CRAN (R 4.2.0)
#>  yaml          2.3.7      2023-01-23 [1] CRAN (R 4.2.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

If we repeat this a couple of times, R warns about closing unused connections like this

Warning messages:
1: In .Internal(gc(verbose, reset, full)) :
  closing unused connection 5 (https://cloud.r-project.org/CRAN_mirrorsZ.csv)
2: In .Internal(gc(verbose, reset, full)) :
  closing unused connection 3 (https://cloud.r-project.org/CRAN_mirrorsZ.csv)
3: In .Internal(gc(verbose, reset, full)) :
  closing unused connection 4 (https://cloud.r-project.org/CRAN_mirrorsZ.csv)

mrcaseb avatar Feb 19 '23 10:02 mrcaseb