microsoft / microsoft/TypeScript

TSServer crash "Cannot read properties of undefined (reading 'sourceFile')" when switching between files in different projects

Aperta
#62,398 6 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@sheetalkamat ci sta già lavorando.

Dal 8/9/2025.

Needs Investigation
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

Type: Bug

Typescript server is frequently crashing when opening files in different TS projects
Image

Repro:
Have multiple files in different typescript projects (ex. a/tsconfig.json, b/tsconfig.json, c/tsconfig.json). Use "jump to definition" from a file in project "a" to files in the other projects quickly, observe tsserver crashed with code "SIGTERM" (not "SIGABRT" from memory issues) with a message "Cannot read properties of undefined (reading 'sourceFile')".

Note: I found https://github.com/microsoft/vscode/issues/229335 reporting this, but there didn't seem to be any resolution there. Happy to provide any followup logs / information to get this fully tracked down this time. I found this stack trace in the error logs consistently:

    Cannot read properties of undefined (reading 'sourceFile')

    TypeError: Cannot read properties of undefined (reading 'sourceFile')
        at isDocumentRegistryEntry (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:143850:18)
        at getDocumentRegistryEntry (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:143926:19)
        at Object.releaseDocumentWithKey (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:144021:19)
        at /Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:152976:65
        at forEach (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:2305:22)
        at cleanupSemanticCache (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:152976:7)
        at Object.dispose (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:152981:5)
        at ConfiguredProject2.close (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:187714:26)
        at ConfiguredProject2.close (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:189310:11)
        at _ProjectService.removeProject (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:190623:13)
        at /Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:192613:33
        at Set.forEach (<anonymous>)
        at _ProjectService.cleanupConfiguredProjects (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:192613:7)
        at _ProjectService.cleanupProjectsAndScriptInfos (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:192616:10)
        at _ProjectService.applyChangesInOpenFiles (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:192864:12)
        at updateOpen (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:194084:29)
        at /Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:196809:15
        at IOSession.executeWithRequestId (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:196798:14)
        at IOSession.executeCommand (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:196807:29)
        at IOSession.onMessage (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typescript.js:196855:68)
        at Interface.<anonymous> (/Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/_tsserver.js:495:14)
        at Interface.emit (node:events:513:28)
        at [_onLine] [as _onLine] (node:internal/readline/interface:416:12)
        at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:610:22)
        at Socket.ondata (node:internal/readline/interface:243:23)
        at Socket.emit (node:events:513:28)
        at addChunk (node:internal/streams/readable:559:12)
        at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
        at Readable.push (node:internal/streams/readable:390:5)
        at Pipe.onStreamRead (node:internal/stream_base_commons:189:23)

with the exit message:

2025-09-04 12:27:19.232 [info] Killing TS Server
2025-09-04 12:27:19.429 [error] TSServer exited. Code: null. Signal: SIGTERM

It definitely feels like some race condition when multiple projects are being opened/closed repeatedly. I'm able to repro it pretty consistently in my monorepo by spamming "going to definition" with the repro above, but it seems to happen often in practice too (or at least our TSServer crashes very often, assuming this repro could be related)

VS Code version: Code - Insiders 1.104.0-insider (Universal) (2617e6ca1619162fd9052c2cabba1d741eb722b8, 2025-09-04T09:27:45.417Z)
OS version: Darwin arm64 24.6.0
Modes:

System Info
Item Value
CPUs Apple M4 Pro (12 x 2400)
GPU Status 2d_canvas: enabled
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: enabled_on
trees_in_viz: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) 4, 5, 6
Memory (System) 24.00GB (1.30GB free)
Process Argv --crash-reporter-id 5e012cc3-e213-44a2-b238-d6c15248dd24
Screen Reader no
VM 0%
Extensions (44)
Extension Author (truncated) Version
vscode-openapi 42C 4.38.0
vscode-altimate-mcp-server alt 0.3.10
sort-imports ama 6.3.1
docker doc 0.16.0
gitlens eam 17.4.1
prettier-vscode esb 11.0.0
nunjucks-template ese 0.5.1
vscode-terminals fab 1.15.0
vscode-github-actions git 0.27.2
gti-vscode Gra 0.6.1
vscode-graphql-execution Gra 0.3.2
vscode-graphql-syntax Gra 1.3.8
vs-color-picker lih 1.0.0
relay met 2.5.1
vscode-containers ms- 2.1.0
vscode-docker ms- 2.0.0
black-formatter ms- 2025.2.0
debugpy ms- 2025.10.0
python ms- 2025.12.0
vscode-pylance ms- 2025.7.1
vscode-python-envs ms- 1.7.12461528
remote-containers ms- 0.426.0
remote-ssh ms- 0.120.0
remote-ssh-edit ms- 0.87.0
remote-wsl ms- 0.104.1
vscode-remote-extensionpack ms- 0.26.0
remote-explorer ms- 0.5.0
remote-server ms- 1.5.2
vscode-js-profile-flame ms- 1.0.9
oracle-java Ora 24.1.0
vscode-thunder-client ran 2.37.7
deoptexplorer-vscode rbu 1.1.2
java red 1.45.0
vscode-commons red 0.0.6
vscode-yaml red 1.18.0
jinjahtml sam 0.20.0
statsig sta 1.1.4
statsig-dev sta 0.0.1
intellicode-api-usage-examples Vis 0.2.9
vscodeintellicode Vis 1.3.2
vscode-gradle vsc 3.16.4
vscode-java-dependency vsc 0.24.1
vscode-java-pack vsc 0.29.2
vscode-maven vsc 0.44.0

(2 theme extensions excluded)

A/B Experiments
vsliv368cf:30146710
pythonvspyt551cf:31249598
nes-control:31372542
nativeloc1:31118317
dwcopilot:31158714
dwoutputs:31242946
copilot_t_ci:31333650
g012b348:31231168
6gi0g917:31259950
996jf627:31264550
pythonrdcb7:31268811
usemplatestapi:31297334
747dc170:31275146
6518g693:31302842
0g1h6703:31329154
agentisdefault:31374427
82j33506:31327384
6abeh943:31336334
envsactivate1:31349248
0927b901:31340060
9ca6-promptcache:31345956
editstats-enabled:31346256
aa_t:31379596
gemagent1cf:31368470
cloudbuttont:31366566
aihoversummaries_f:31371859
todos-0:31366869
codex-prompt:31370221
search_len3:31379603
multireplacestring:31375832
nb255704_tf:31377673
3efgi100_wstrepl:31374188
metis-embeddings:31380188
trigger-command-fix:31379601

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.