fix: clear timeout after promise rejection#24864
Merged
Hona merged 1 commit intoanomalyco:devfrom Apr 28, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a process-liveness leak in withTimeout by ensuring the timeout handle is cleared when the wrapped promise rejects, not just when it fulfills. This prevents large batches of fast-failing operations from leaving long-lived timers pending and keeping the process alive.
Changes:
- Replace
promise.then(...)withpromise.finally(...)soclearTimeout(timeout)runs on both fulfill and reject paths.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
afanty2021
added a commit
to afanty2021/opencode
that referenced
this pull request
Apr 29, 2026
Upstream commits: - fix: clear timeout after promise rejection (anomalyco#24864) - chore: generate - fix(bash): memory leak - release parsed syntax trees (anomalyco#24861) - feat(core): filter sessions by path and add setting to disable (anomalyco#24849) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> # Conflicts: # packages/core/CLAUDE.md # packages/core/src/util/CLAUDE.md
oleksii-honchar
pushed a commit
to oleksii-honchar/better-opencode
that referenced
this pull request
Apr 29, 2026
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.
Summary
withTimeouttimers when the wrapped promise rejects, not only when it fulfills.Repro
I reproduced this with 10,000 rejected promises wrapped in
withTimeout(..., 60_000).Before this change, all promises settled quickly, but the process stayed alive because the 60s timers were still pending.
After this change, the same repro exits immediately after the rejected promises settle.
User-Facing Impact
This does not make successful actions faster. It only matters when a wrapped operation rejects quickly before its timeout.
30safter it otherwise finished45sif you exit right after3sopencodeexit may hang up to5sIn normal long-running TUI/server usage, users probably will not notice. This is mostly an
opencodedoes not exit promptly after a failure cleanup bug, not action latency.Scope
This is a bounded timer/process-exit leak, not an unbounded native memory leak. The affected callsites are MCP connect/list-tools, LSP initialize/diagnostics, and TUI worker shutdown.
Verification
withTimeout(..., 60_000)exits in under 1sbun typecheckfrompackages/opencodebun turbo typecheck