Repository navigation
fix(api): retain snapshot across concurrent queries and reject post-close registration - #8
Draft
robertpenner wants to merge 3 commits into
Draft
robertpenner wants to merge 3 commits into
robertpenner wants to merge 3 commits into
Conversation
…lose registration
…anguageServerSnapshot
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 #3
Summary
Fixes two snapshot lifecycle bugs in
api.Session(tsc/internal/api/session.go,tsc/internal/api/module_resolution.go):s.snapshots[handle]viagetSnapshotDatapreviously unlockedsnapshotsMu.RLock()without retaining the underlying*project.Snapshot, allowing a concurrenthandleReleaseorSession.Close()to disposesd.snapshotmid-query.Session.Close()cleareds.snapshotswithout recording a closed flag, allowing a concurrentregisterSnapshot()to insert and leak a retained*project.SnapshotafterClose()completed.Fix
sd.refCountstrictly for client-owned references (registerSnapshot/handleRelease).getSnapshotData(handle)to retainsd.snapshotvias.snapshotHost.RetainSnapshot(sd.snapshot)unders.snapshotsMu.RLock()and return an idempotentreleasecallback (sync.OnceFunccallingsd.snapshot.Deref()). ReplaceretainSnapshotDatawithgetSnapshotDataso snapshot derivation is also protected againstSession.Close()and duplicatehandleRelease.checkerSetup.done,resolveSymbolReference's returned release callback,getEmitProgram/getEmitOptions, and all directgetSnapshotDatahandlers.closed boolguarded bys.snapshotsMu:Close()setss.closed = truebefore clearings.snapshots;registerSnapshot()checkss.closed, derefs the snapshot immediately if closed, and returns an error.Verification
ApiSessionSnapshot_Fixed.cfgontla-concurrency-verification): 0 errors across 36 distinct states (69 generated) with deadlock checking enabled, verifyingNoUseAfterDeref,NoLeakAfterClose,NoNegativeSnapRef, andQuiescentClean.go -C ./tsc test -race -count=1 ./internal/api/...: all 4 packages pass (api,encoder,requestfilesystem,wasmreactor), includingTestGetSnapshotDataRetainsAcrossRelease,TestGetSnapshotDataRetainsAcrossSessionClose, andTestRegisterSnapshotAfterCloseRejectsAndDerefs.gofmtandgo vet ./internal/api/...: clean.