Skip to content

Fix api.Session post-close leaks across LSP refs, source file leases, batch pages, and unstopped cpuProfiler (tsc/internal/api/session.go) #22

Backlog

Description

@robertpenner

Parent / source

What to build

Enforce a monotonic closed state across the three remaining resource tables in tsc/internal/api/session.go and stop any active CPU profiler in Session.Close():

  1. LSP reference leak (NoPostCloseLspRefLeak): Session.Close() (session.go:5789-5810) calls releaseLanguageServerRefs() (session.go:5812-5844) under s.languageServerUpdateMu without marking the session closed. A concurrent handleGetCurrentLanguageServerSnapshot (session.go:1892-1929) acquiring s.languageServerUpdateMu afterward calls s.projectSession.APIUpdate and leaks open projects, files, or synthetic programs into the live shared LSP project.Session permanently (s.closeOnce already fired).
  2. Source-file lease leak (NoPostCloseLeaseLeak): registerSourceFileLease (session.go:2339-2345) acquires s.sourceFileLeasesMu and stores a lease without checking whether releaseSourceFileLeases() (session.go:2419-2430) already ran, pinning *ast.SourceFile refcounts in the shared parseCache.
  3. Batch continuation page leak (NoPostCloseBatchPageLeak): paginateBatchResponses (session.go:1349-1394) stores pages into s.batchResponsePages (session.go:1390) with no closed check or synchronization against s.batchResponsePages.Clear() (session.go:5808).
  4. Unstopped cpuProfiler on disconnect: Session.Close() never stops s.cpuProfiler (session.go:1448-1455) if a client disconnects mid-profile.

Required observable behavior:

  • After Session.Close() begins releasing each table, concurrent or subsequent handleGetCurrentLanguageServerSnapshot, registerSourceFileLease, and paginateBatchResponses cannot insert new entries or leak open LSP refs/leases/batch pages (releasing any newly acquired lease immediately if closed).
  • Session.Close() stops an active s.cpuProfiler if present.

Decisions and constraints

Acceptance criteria

  1. Green TLA+ model: Already verified in ApiSessionLifecycle_Fixed.cfg (exit 0).
  2. Go fix and regression tests: On a clean fix branch off main (e0fce98), fix tsc/internal/api/session.go and add in-package -race regression tests porting all 3 reproducers (plus cpuProfiler cleanup if testable cleanly).
  3. Verification: go -C ./tsc test -race -timeout=120s ./internal/api/... passes.

Starting references

  • tsc/internal/api/session.go:1349-1394 (paginateBatchResponses)
  • tsc/internal/api/session.go:1448-1465 (cpuProfiler)
  • tsc/internal/api/session.go:1892-1929 (handleGetCurrentLanguageServerSnapshot)
  • tsc/internal/api/session.go:2339-2345, 2419-2430 (registerSourceFileLease, releaseSourceFileLeases)
  • tsc/internal/api/session.go:5789-5844 (Session.Close, releaseLanguageServerRefs)
  • verification/tla/specs/ApiSessionLifecycle/ApiSessionLifecycle.tla
  • verification/tla/reproducers/api_session_tier3_repro_test.go

Activity

  1. added
    bug
    ready-for-agent
    on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions