Skip to content

exec: detaches scope finaliser on termination - #64

Merged
lePereT merged 1 commit into
nextfrom
term-cleanup
Jun 4, 2026
Merged

exec: detaches scope finaliser on termination#64
lePereT merged 1 commit into
nextfrom
term-cleanup

Conversation

@lePereT

@lePereT lePereT commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this? (check all applicable)

  • 🐛 Bug Fix
  • ✅ Test

Description

Fixes a lifetime leak in fibers.io.exec where completed commands retained their scope finaliser until the parent scope exited.

Previously, each command registered a scope finaliser when started. Commands that completed normally kept that finaliser attached, which retained the command object and associated process/stream/backend state for the lifetime of the parent scope. In long-lived scopes that repeatedly run short commands, this caused completed exec commands to accumulate.

Changes:

  • Detach the command scope finaliser once the command reaches a terminal state.
  • Release owned stdin/stdout/stderr streams and backend process references after terminal status is cached.
  • Preserve repeated run_op() / wait semantics by returning cached terminal status on subsequent waits.
  • Keep shutdown and scope-exit cleanup idempotent.
  • Add a regression test covering completed-command finaliser detachment.
  • Extend the regression to verify repeated waits still return the same terminal status.

Manual test

  • 👍 yes

Manual test description

Ran the full fibers test suite successfully with both Lua and LuaJIT.

The new regression test verifies that completed commands detach their scope finalisers before scope exit, and that repeated waits on a completed command continue to return the same status.

Added tests?

  • 👍 yes

Added to documentation?

  • 🙅 no documentation needed

@lePereT
lePereT merged commit 9517d3b into next Jun 4, 2026
1 check passed
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