Release run_r sink and connection on interrupt - #216
Merged
Merged
Conversation
The supervised worker aborts an over-deadline run_r with an interrupt. That interrupt unwinds past tool_run_r()'s error-only tryCatch without reaching close_stream(), so every timeout left a sink, its file connection, and the temp file open in the persistent worker. With no ceiling, repeated timeouts accumulate sinks, connections, and files across a long run. Move the sink, connection, and temp-file cleanup into on.exit(), which fires on interrupts as well as errors and normal returns. The sink_open and con_open flags keep it idempotent with the explicit normal-path close that must still run before the stream file is read back. Adds a repeated-interrupt regression test that drives three interrupts through tool_run_r() and asserts sink and connection counts return to baseline and a following print() is still captured.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The supervised
run_rworker aborts an over-deadline call with an interrupt (R/run-r-worker.R). That interrupt unwinds pasttool_run_r()'s error-onlytryCatch, soclose_stream()never runs. Every timeout left asink, its file connection, and the temp file open in the persistent worker; over a long run these accumulate with no ceiling.Fix
Move the sink, connection, and temp-file cleanup into
on.exit(), which fires on interrupts as well as on errors and normal returns. Thesink_openandcon_openguards keep it idempotent with the explicit normal-path close that must still run before the stream file is read back.Test
Adds a repeated-interrupt regression test in
test_run_r_streams.R: three interrupts driven throughtool_run_r(), asserting sink and connection counts return to baseline and a followingprint()is still captured.