Skip to content

fix(cli): avoid accumulating sandbox proxy exit handlers across launches #24334

@jasonmatthewsuhari

Description

@jasonmatthewsuhari

Summary

The sandbox proxy setup path registers fresh process exit/signal handlers every time a proxy is started, but attempts to remove old handlers using a newly-created function identity. That does not actually detach the previously-registered handlers.

Evidence

In packages/cli/src/utils/sandbox.ts, both proxy setup paths create a new stopProxy closure and then call process.off('exit', stopProxy) / process.on('exit', stopProxy) (and similarly for SIGINT/SIGTERM). Because the function is recreated on each launch, process.off(...) only refers to the new closure and cannot remove earlier registrations.

Impact

Repeated sandbox launches in the same process can accumulate duplicate exit/signal handlers. This can cause duplicated cleanup attempts, noisy teardown behavior, and eventual listener-growth issues in long-lived CLI sessions.

Expected behavior

Proxy cleanup handlers should be registered once per live proxy instance and reliably removed when the proxy is torn down.

Suggested fix

Track the active cleanup handler explicitly and unregister the exact same function reference during teardown before installing a replacement.

Metadata

Metadata

Assignees

Labels

area/platformIssues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmtpriority/p1Important and should be addressed in the near term.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions