fix: dispose SettingsManager on session close to prevent resource leaks#454
Conversation
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Tahar BOUNSIAR.
|
SettingsManager was never disposed when sessions were closed or when the Claude Agent process died unexpectedly. Each leaked session left up to 4 active fs.watch() file descriptors and a pending debounce timer, causing resource exhaustion on long-running instances.
b2a1374 to
7837f2b
Compare
|
We require contributors to sign our Contributor License Agreement, and we don't have @tbounsiar on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
@cla-bot check |
|
We require contributors to sign our Contributor License Agreement, and we don't have @tbounsiar on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
…485) ## Summary - **Concurrent `setCwd()` calls** could produce duplicate file watchers because both calls cleared `initialized` before either completed `initialize()`. Added an `initPromise` guard so concurrent calls await the same initialization. - **Debounce timer callback** could fire after `dispose()`, reloading stale settings and calling `onChange` on a disposed manager. Added a `disposed` flag checked in the async callback before proceeding. Follows up on #454 which fixed the missing `dispose()` calls — this PR hardens the `SettingsManager` lifecycle against race conditions. ## Test plan - [x] `npm run lint` passes - [x] All settings tests pass - [x] Verified `disposed` flag prevents stale callback execution - [x] Verified `initPromise` deduplicates concurrent `initialize()` calls
Summary
SettingsManager.dispose()was never called when a session was closed viaunstable_closeSessionor when the Claude Agent process died unexpectedlyfs.watch()file descriptors and a pending debounce timersession.settingsManager.dispose()in both cleanup paths and updated test mocks to assert the callTest plan
npm run buildcompiles cleannpm run lintpassessession/closetests updated to verifydispose()is called