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

Recursive gc error #389

Closed
hadley opened this issue Dec 1, 2021 · 3 comments · Fixed by #390
Closed

Recursive gc error #389

hadley opened this issue Dec 1, 2021 · 3 comments · Fixed by #390
Assignees

Comments

@hadley
Copy link
Member

hadley commented Dec 1, 2021

library(dplyr)
library(nycflights13)
library(magrittr)

path <- tempfile()
dir.create(path)

gctorture(TRUE)

flights %>% 
  group_by(month) %>% 
  group_walk(~ vroom::vroom_write(.x, sprintf("%s/month-%02i.csv", path, .y$month)))
*** recursive gc invocation
*** recursive gc invocation
Error in vroom_write_(xx, file, delim, eol, na_str = na, col_names = col_names,  :
  cannot get ALTSTRING_ELT during GC
Error: no more error handlers available (recursive errors?); invoking 'abort' restart
sive gc invo>c aion
** ecrsvegcinoctin
** ecursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
Error: no more error handlers available (recursive errors?); invoking 'abort' restart
Error: no more error handlers available (recursive errors?); invoking 'abort' restart
Error: no more error handlers available (recursive errors?); invoking 'abort' restart
Error: no more error handlers available (recursive errors?); invoking 'abort' restart
Error: no more error handlers available (recursive errors?); invoking 'abort' restart

From tidyverse/multidplyr#127 (comment)

@DavisVaughan
Copy link
Member

Possibly related is #270, which claims that all ALTREP columns are converted to non-ALTREP before writing

@DavisVaughan
Copy link
Member

I think the problem is with the POSIXct column.

vroom calls vroom_convert() to materialize any ALTREP columns here, but then immediately calls output_column() to perform any necessary type conversion before writing. The POSIXct->character conversion will actually create another ALTREP wrapper object.

https://github.com/r-lib/vroom/blob/0ea9d8c96eade582a695632a3be5dc45c7e0fff4/R/vroom_write.R#L66-L69

# Make it large enough to trigger an ALTREP wrapper
x <- rep(as.POSIXct("2019-01-01", "UTC"), 1000)

# This makes an ALTREP character vector, oops
.Internal(inspect(vroom:::output_column(x)))
#> @7fefac305790 16 STRSXP g0c0 []  wrapper [srt=-2147483648,no_na=0]
#>   @7fef6b10a000 16 STRSXP g0c7 [REF(1)] (len=1000, tl=0)
#>     @7fefabfc4c98 09 CHARSXP g0c3 [REF(1001),gp=0x60] [ASCII] [cached] "2019-01-01T00:00:00Z"
#>     @7fefabfc4c98 09 CHARSXP g0c3 [REF(1001),gp=0x60] [ASCII] [cached] "2019-01-01T00:00:00Z"
#>     @7fefabfc4c98 09 CHARSXP g0c3 [REF(1001),gp=0x60] [ASCII] [cached] "2019-01-01T00:00:00Z"
#>     @7fefabfc4c98 09 CHARSXP g0c3 [REF(1001),gp=0x60] [ASCII] [cached] "2019-01-01T00:00:00Z"
#>     @7fefabfc4c98 09 CHARSXP g0c3 [REF(1001),gp=0x60] [ASCII] [cached] "2019-01-01T00:00:00Z"
#>     ...

It looks to me like it would be safe to just swap the ordering of these two calls, and that should fix it.

I'm trying to run the original example to try and reproduce the issue right now. Very slow!

@DavisVaughan
Copy link
Member

DavisVaughan commented Dec 1, 2021

Slightly more minimal reprex:

library(nycflights13)
library(vroom)

path <- tempfile(fileext = ".csv")

gctorture(TRUE)

vroom_write(flights, path)

And I confirmed that this does not fail, so I think my analysis is correct

library(nycflights13)
library(vroom)

path <- tempfile(fileext = ".csv")

flights$time_hour <- NULL

gctorture(TRUE)

vroom_write(flights, path)

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

Successfully merging a pull request may close this issue.

2 participants