Skip to content

Code causes TS Server to hang using 100% CPU and become non-responsive #23458

Closed
@kpdonn

Description

@kpdonn

TypeScript Version: 2.9.0-dev.20180414 (also reproduces in 2.8.1)

Search Terms:
TSServer, CPU, autocomplete

Code

recordautocompletebug

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:

  1. Clone https://github.com/kpdonn/kpd-sql/tree/autocompleteHangsBug (note the autocompleteHangsBug branch)
  2. Run yarn to get dependencies
  3. Open typings-tests/autocompleteBug.ts in VS Code.
  4. 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.
  5. 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.

Related Issues:
Possibly #23390, #23259 or #23389.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions