Skip to content

Release run_r sink and connection on interrupt - #216

Merged
TroyHernandez merged 2 commits into
mainfrom
fix-run-r-timeout-cleanup
Sep 17, 2026
Merged

TroyHernandez merged 2 commits into
mainfrom
fix-run-r-timeout-cleanup

Conversation

@TroyHernandez

Copy link
Copy Markdown
Contributor

Problem

The supervised run_r worker aborts an over-deadline call with an interrupt (R/run-r-worker.R). That interrupt unwinds past tool_run_r()'s error-only tryCatch, so close_stream() never runs. Every timeout left a sink, 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. The sink_open and con_open guards 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 through tool_run_r(), asserting sink and connection counts return to baseline and a following print() is still captured.

  • Before: 3 interrupts -> 3 leaked sinks + 3 leaked connections.
  • After: 3 interrupts -> 0 leaked.
  • Full suite: 4864 asserts, 0 failures.

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.
@TroyHernandez
TroyHernandez merged commit a65b087 into main Sep 17, 2026
2 checks passed
@TroyHernandez
TroyHernandez deleted the fix-run-r-timeout-cleanup branch September 17, 2026 23:02
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 this pull request may close these issues.

1 participant