Description
TypeScript Version: 2.9.0-dev.20180414 (also reproduces in 2.8.1)
Search Terms:
TSServer, CPU, autocomplete
Code
Steps to reproduce
Unfortunately I haven't been able to produce a self contained reproduction, but I can reproduce it consistently in the project I'm working on using just the code above. Specific steps:
- Clone https://github.com/kpdonn/kpd-sql/tree/autocompleteHangsBug (note the
autocompleteHangsBug
branch) - Run
yarn
to get dependencies - Open
typings-tests/autocompleteBug.ts
in VS Code. - Type
db.with("a", db.
in that file and try to autocomplete. Note that actually typing it does matter. It does not reproduce for me if not manually typed. - The TS service hangs and stops responding to any requests. CPU on my machine (macOS) shoots up to 100% and stays there.
Logs
I enabled verbose tsserver trace logs, however the only output it logs once it starts hanging is the following.
[Trace - 00:06:49] TypeScript Service: canceled request with sequence number 46
[Trace - 00:06:50] TypeScript Service: canceled request with sequence number 49
[Trace - 00:06:50] TypeScript Service: canceled request with sequence number 51
[Trace - 00:06:55] TypeScript Service: canceled request with sequence number 55
[Trace - 00:06:56] TypeScript Service: canceled request with sequence number 57
[Trace - 00:06:57] TypeScript Service: canceled request with sequence number 58
[Trace - 00:06:57] TypeScript Service: canceled request with sequence number 59
[Trace - 00:06:58] TypeScript Service: canceled request with sequence number 60
[Trace - 00:06:59] TypeScript Service: canceled request with sequence number 61
I didn't see any stack traces or anything that seemed interesting before those lines start appearing, but if providing the logs will help let me know and I'll add them.
What triggers it
I don't have any idea what the root cause is, but I know what makes it start happening. This change in everything.ts.
When I remove BeforeSelect
that was added there try to follow the steps to reproduce it again(after restarting tsserver), it no longer happens. BeforeSelect
is a mapped type that filters out a handful of methods from SqlBuilder
. The code creating the types is pretty complicated, but I don't know why that specifically triggers the problem.