Skip to content

Cannot read properties of undefined (reading 'close') #49961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mjbvz opened this issue Jul 19, 2022 · 3 comments · Fixed by #49990
Closed

Cannot read properties of undefined (reading 'close') #49961

mjbvz opened this issue Jul 19, 2022 · 3 comments · Fixed by #49990
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Jul 19, 2022

Bug Report

🔎 Search Terms

  • watcher
  • crash

🕗 Version & Regression Information

4.8.0-dev.20220711

Seems like a regression as I do not remember seeing this in TS 4.7

Details

When closing editors in VS Code, recently I've been seeing the following crash:

  ERR <semantic> TypeScript Server Error (4.8.0-dev.20220711)
Cannot read properties of undefined (reading 'close')
TypeError: Cannot read properties of undefined (reading 'close')
    at Object.close (/Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:6834:29)
    at Object.close (/Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:116840:29)
    at closeFileWatcherOf (/Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:116891:32)
    at Map.forEach (<anonymous>)
    at Object.clearMap (/Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:19668:13)
    at Object.clear (/Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:122531:16)
    at ConfiguredProject.Project.close (/Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:171446:38)
    at ConfiguredProject.close (/Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:172930:40)
    at ProjectService.removeProject (/Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:173991:25)
    at /Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:175861:86
    at Map.forEach (<anonymous>)
    at ProjectService.removeOrphanConfiguredProjects (/Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:175861:44)
    at ProjectService.cleanupAfterOpeningFile (/Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:175805:22)
    at ProjectService.applyChangesInOpenFiles (/Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:176009:26)
    at Session.handlers.ts.Map.ts.getEntries._a.<computed> (/Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:177372:46)
    at /Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:179564:96
    at IpcIOSession.Session.executeWithRequestId (/Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:179555:28)
    at IpcIOSession.Session.executeCommand (/Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:179564:41)
    at IpcIOSession.Session.onMessage (/Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:179592:35)
    at process.<anonymous> (/Users/matb/projects/vscode/node_modules/typescript/lib/tsserver.js:183758:31)
    at process.emit (node:events:390:28)
    at emit (node:internal/child_process:917:12)
    at processTicksAndRejections (node:internal/process/task_queues:84:21): Error: <semantic> TypeScript Server Error (4.8.0-dev.20220711)

I can't repo this reliably but here's the complete log of a session the crashed (it's quite large)
tsserver.log.zip

@DanielRosenwasser
Copy link
Member

First error in logs is possibly #49310

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jul 20, 2022
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.8.1 milestone Jul 20, 2022
@jakebailey
Copy link
Member

Based on the trace (closeFileWatcherOf followed by two close calls), I think this is caused by a double-close of this watcher:

watcher = undefined!;

It's not clear to me from the API of FileWatcher whether or not a double close is intended to be to be legal (I'll add some asserts to various implementations to check), but I think making this one not crash is straightforward.

@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Jul 21, 2022
@jakebailey
Copy link
Member

I can't say I know for sure if the API should allow double closes or not; there are clearly some refcounted file watchers which just start returning early once their references are up. There are also some other cases (different from this issue's trace) which could potentially crash if some invariant were violated, but we a aren't seeing those. So I'm inclined to go the safer route that doesn't do a undefined!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants