Skip to content
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

Make watcher symlink-aware (currently follows symlinks) #23418

Closed
Swatinem opened this issue Apr 15, 2018 · 3 comments
Closed

Make watcher symlink-aware (currently follows symlinks) #23418

Swatinem opened this issue Apr 15, 2018 · 3 comments

Comments

@Swatinem
Copy link
Contributor

TypeScript Version: 2.8.1

Search Terms:

  • watch
  • symlink

AFAICS there is actually a lot of issues related to this.

Code

There is not really any code to show.
We do have a mono-repo, that for some issues with one of our dependencies creates manual symlinks between out packages.

Expected behavior:

Things should work

Actual behavior:

When I do a tsc --watch, it takes roughly ~30s to watch all the files, because it actually follows the symlinks.
When running tsserver, either via code or typescript-language-server, the process hangs for >60s with 100% cpu usage. I have attached a debugger and found out that all the time is spent following symlinks and watching those files.
Here is a screenshot of a short profile I have done:

bildschirmfoto von 2018-04-15 17-19-01
(The profile only shows ~18s worth of directory walking, but in reality its way more.

Also, the tsserver process uses in excess of ~1400M of RAM, so it may also explain some of the OOM bugs that I have found with the search.

Playground Link:

Related Issues:

I think #10873 would be an extreme example of this
Otherwise there is a lot of issues mentioning watch mode and extremely slow performance, some of those mention mono-repos, so I guess a lot of this is related.

@Swatinem
Copy link
Contributor Author

So just as an experiment, I changed this statSync here:
https://github.com/Microsoft/TypeScript/blob/23ed9f842301ab8c7894823afc7a356da960adcf/src/compiler/sys.ts#L995
to lstatSync (which according to https://nodejs.org/api/fs.html#fs_fs_lstat_path_callback returns info on the link itself, and therefore returns false for isDirectory())

That single line change basically fixed the hangs for me.

Of course if you want to properly fix this, you would have to maintain a Map of already walked directories and perform a lookup there if you encounter a symlink.

Maybe I will work on a patch tomorrow. Is there anything specific I need to keep in mind when doing that?

@Swatinem
Copy link
Contributor Author

Hm, so apparently this was already fixed in #22976 / #22986, but it is not yet included in a stable release, although 2.8.2 was tagged, it is not yet on npm -_-

So sorry for the inconvenience :-(

@j-oliveras
Copy link
Contributor

Info about next release on npm: #23282.

@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants