fix: clean up orphaned processes and LSP state on shutdown#20006
Open
nianyi778 wants to merge 2 commits intoanomalyco:devfrom
Open
fix: clean up orphaned processes and LSP state on shutdown#20006nianyi778 wants to merge 2 commits intoanomalyco:devfrom
nianyi778 wants to merge 2 commits intoanomalyco:devfrom
Conversation
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #12767
Related to #18632
Type of change
What does this PR do?
This fixes two shutdown paths that still look leaky on current
dev.First,
packages/opencode/src/index.tsdoes not register process-level handlers forSIGTERM,SIGHUP, orSIGPIPE. The TUI has its ownSIGHUPhandling, but commands likeopencode run,opencode acp, andopencode servedo not. This PR adds a smallsignal.tshelper that callsInstance.disposeAll()and then exits, with a 5 second timeout in case cleanup hangs.Second, LSP shutdown was stopping the child process but keeping in-memory state alive. This clears the LSP diagnostics map, file version map, and the top-level LSP client caches during shutdown.
I also clear the prompt
msgsarray right afterprocessor.process(...)returns, since that array can get large and is not needed for the rest of the loop iteration.I did not copy over older PR changes around plugin subscriptions or processor cleanup because current
devalready uses scoped Effect subscriptions there, andSessionProcessoralready runs cleanup throughEffect.ensuring(cleanup()).How did you verify your code works?
I tested the signal path locally with the ACP command, since it is a long-running non-TUI entrypoint:
bun run ./src/index.ts acpSIGHUPSIGTERMI also tried to run
bun typecheckinpackages/opencode, but this checkout currently does not havetsgoinstalled innode_modules/.bin, so the script exits before typechecking starts.Screenshots / recordings
N/A
Checklist