Fix Windows lifecycle management with multi-layered defense #415
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
Fixes critical process lifecycle issues on Windows where serve-d and its child processes (dcd-server) would remain running after the editor closed, causing resource leaks and preventing the editor from restarting properly.
Problem Statement
Symptoms
Root Causes
paramswasnull, causing editors to give up on graceful shutdownscope(exit)wasn't reliableSolution
This PR implements a multi-layered defense system to ensure proper cleanup in all scenarios:
Layer 1: Accept Null Params in Shutdown Requests
File:
lsp/source/served/lsp/jsonrpc.dModified JSON-RPC parameter validation to accept
"params":nullin addition to objects and arrays, per LSP specification.Layer 2: Windows Job Objects with Self-in-Job
File:
serverbase/source/served/utils/jobs.d(NEW)Complete Windows Job Objects implementation including:
KILL_ON_JOB_CLOSEflagLayer 3: Lifecycle Integration
File:
serverbase/source/served/serverbase.dscope(exit)ofrun()method - executes regardless of how function exitsprocessNotify()for explicit exit/shutdown pathsLayer 4: DCD Server Integration
File:
workspace-d/source/workspaced/com/dcd.daddProcessToJobByProcessPipes()method instead of reopening by PIDworkspace-d/dub.sdl)How It Works
Normal Exit
scope(exit)cleanup runscleanupJobObject()closes the Job Object handleAbrupt Exit (Red X, Force Kill, Crash)
KILL_ON_JOB_CLOSEflag causes Windows kernel to kill all child processesTesting
Tested on Windows 10 with Zed editor:
Compatibility
version(Windows))Files Changed
lsp/source/served/lsp/jsonrpc.d- Accept null params in shutdownserverbase/source/served/utils/jobs.d- NEW - Complete Job Objects implementationserverbase/source/served/serverbase.d- Lifecycle integration with scope(exit) cleanupworkspace-d/source/workspaced/com/dcd.d- Add DCD to Job Objectworkspace-d/dub.sdl- Add serverbase dependencyPerformance Impact
Negligible:
Breaking Changes
None - all changes are additive bugfixes.
Resolves issues with orphaned serve-d and dcd-server processes on Windows.