Ensure that prev_mask
is always protected
#256
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes tidyverse/dplyr#6207
The most minimal reprex I could come up with to show this issue was:
Which would often error with:
This only happened when there were >=2 pipes in a pipe chain, and didn't happen at all when the pipes were removed. We also had to be very aggressive with
gctorture2()
to get it to show up at all, so it was probably very rare.It turns out that as we are updating
prev_mask
and moving from one iteration of thewhile
loop to the next, there is a very short window whereprev_mask
is unprotected and can be gc'd. On the second iteration of thewhile
loop, right afterREPROTECT(mask, mask_pi);
theprev_mask
becomes unprotected. The first line ofr_env_bind_lazy()
runs an allocating function, which is when it is possible forprev_mask
to become gc'd. You can force this to happen reliably by placingR_gc();
right after theREPROTECT(mask, mask_pi);
line and running the reprex above.