Skip to content

fix: finish() now cleans up on exception - #282

Draft
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-finish-cleanup-on-exception
Draft

fix: finish() now cleans up on exception#282
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-finish-cleanup-on-exception

Conversation

@toddr-bot

Copy link
Copy Markdown
Contributor

What

finish() now properly cleans up pipes, children, and fds when _select_loop() throws an exception (e.g., timeout).

Why

When _select_loop() threw inside finish(), the exception propagated past _cleanup(), leaking pipes and leaving child processes unrepaped. run() handled this correctly via eval + kill_kill, but the async API path (start/pump/finish) had no safety net. Any user calling finish() with a timeout would leak resources on expiration.

How

Wrapped the pump loop in eval and call kill_kill() on failure, matching run()'s pattern. kill_kill() sends SIGTERM, waits for children, then calls _cleanup() — ensuring all resources are released even on error.

Testing

  • New test file t/finish_cleanup.t (4 tests): timeout exception propagation, harness finished state, no fd leak, children reaped
  • Full test suite: 867 tests pass (t/pty.t skipped — IO::Pty version)

🤖 Generated with Claude Code

When _select_loop() threw inside finish() (e.g., timeout expiration),
the exception propagated past _cleanup(), leaking pipes and leaving
child processes unrepaped. run() handled this correctly via eval +
kill_kill, but the async API path (start/pump/finish) had no safety
net.

Now finish() wraps the pump loop in eval and calls kill_kill() on
failure, matching run()'s behavior. This ensures children are
signaled, reaped, and pipes are closed even when an exception occurs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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