Repository navigation
fix(lsp): preserve $/cancelRequest for queued client requests - #7
Draft
robertpenner wants to merge 2 commits into
Draft
robertpenner wants to merge 2 commits into
robertpenner wants to merge 2 commits into
Conversation
This was referenced Nov 26, 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.
Closes #2
Summary
Fixes a race in
lsp.Server(tsc/internal/lsp/server.go) where$/cancelRequestnotifications were silently dropped when their target request was still waiting ins.requestQueueahead ofdispatchLoop.Root Cause
readLooppreviously enqueued incoming client requests intos.requestQueuewithout recording them ins.pendingClientRequests, whiledispatchLooppopulateds.pendingClientRequestsonly after dequeuing. BecausereadLoopintercepts$/cancelRequestimmediately againsts.pendingClientRequests, any cancellation arriving while the target request sat behind preceding edits or notifications ins.requestQueuemisseds.pendingClientRequestsand was discarded.Fix
pendingClientRequestwith acanceled boolflag (cancelremainsnilwhile queued).s.pendingClientRequestsinreadLoopbefores.requestQueue.Put(ctx, req)(deleting onPutfailure).cancelRequest: if an entry has a non-nilcancel, invoke it and delete; if queued (cancel == nil), markcanceled = true; if absent, no-op (no map growth on unknown or duplicate cancels).dispatchLoop: checkpendingReq.canceledafter popping; if already canceled while queued, delete the entry, respond immediately withlsproto.ErrorCodeRequestCancelled, and skip running the handler.requestCtxis still constructed indispatchLoop, preserving locale ordering after preceding notifications.Verification
LspServerCancel_Fixed.cfgontla-concurrency-verification): 0 errors across 30 distinct states (45 generated) with deadlock checking enabled, verifyingNoDroppedCancellation,NoLeakedPendingEntries, andCanceledRequestRespondsCancelled.go -C ./tsc test -race -count=1 ./internal/lsp/...: all 3 packages pass (lsp,lsproto,lspwatcher), includingTestCancelRequestWhileQueuedInRequestQueueandTestCancelActiveRequestCancelsContext.gofmtandgo vet ./internal/lsp/...: clean.