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

TypeScript installs file watchers, ignoring files.watcherExclude setting #183177

Closed
jelmd opened this issue May 23, 2023 · 15 comments
Closed

TypeScript installs file watchers, ignoring files.watcherExclude setting #183177

jelmd opened this issue May 23, 2023 · 15 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug *duplicate Issue identified as a duplicate of another issue(s) file-watcher File watcher typescript Typescript support issues

Comments

@jelmd
Copy link

jelmd commented May 23, 2023

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.78.2
  • OS Version: Linux (Ubuntu 20.04)

Steps to Reproduce:

  1. mkdir myapp

cat >package.json<<EOF
{
"name": "foobar",
"description": "Test",
"repository": "https://github.com/x/y",
"bugs": {
"url": "https://github.com/x/y/issues"
},
"author": "Foo Bar [email protected]",
"contributors": [],
"version": "0.1.0",
"private": true,
"scripts": {
"db": "NODE_OPTIONS='--no-warnings --loader ts-node/esm' nodemon --watch scripts scripts/db.ts",
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"clean": "rm -rf .next",
"realclean": "rm -rf .next node_modules package-lock.json"
},
"dependencies": {
"@next-auth/prisma-adapter": "^1.0.6",
"@prisma/client": "^4.14.1",
"next": "13.4.3",
"nodemailer": "^6.9.2",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@styled-icons/material": "^10.47.0",
"@styled-icons/fa-solid": "^10.47.0",
"@types/busboy": "^1.5.0",
"@types/node": "20.2.3",
"@types/nodemailer": "^6.4.8",
"@types/react": "18.2.6",
"@types/react-dom": "18.2.4",
"eslint": "8.41.0",
"eslint-config-next": "13.4.3",
"prisma": "^4.14.1",
"typescript": "5.0.4"
}
}
EOF
4. npm i
5. with super user privileges: sysctl fs.inotify.max_user_watches=4096
6. adjust excludes in ~/.config/Code/User/settings.json. E.g.:

{
   "files.watcherExclude": {
        "**/.git/objects": true,
        "**/.git/subtree-cache": true,
        "**/.nfs*": true,
        "**/*.swp": true,
        "**/node_modules": true,
        "**/.next": true
    },
 }
  1. code .

No matter, what you specify, code still watches all directories, even so it is not desired at all to watch anything below ./node_models/. In the example above these are ~ 4K directories. This is a huge waste of resources and should be fixed (beside it causes other problems with other misbehaving apps, which do similar insane things ...).

To inspect inotify watches in a very easy way, it is highly recommended to use a tool like inotify-info!

@jelmd
Copy link
Author

jelmd commented May 23, 2023

FWIW: If I set the limit to 16K, code uses 8030 watches for no reason.

@bpasero
Copy link
Member

bpasero commented May 23, 2023

It is possible that not VS Code's file watcher is watching these large folders but an extension. As such:

Is the issue caused by an Extension?

Stop VS Code and from the command line (NOT the integrated terminal in Code), execute: code --disable-extensions and try your steps again to see if it reproduces. If it still reproduces, jump to the next chapter.

If you see it is an issue with the extension, please run the command Start Extension Bisect and follow the instructions to find the extension that is causing this issue.

image

Please report the issue to the extension causing this.

@bpasero bpasero added the info-needed Issue requires more information from poster label May 23, 2023
@jelmd
Copy link
Author

jelmd commented May 23, 2023

--disable-extensions doesn't change anything:

> inotify-info
------------------------------------------------------------------------------
INotify Limits:
  max_queued_events    16384
  max_user_instances   128
  max_user_watches     16384
------------------------------------------------------------------------------
        Pid  App                        Watches   Instances
      625735 code                           7973   1
        4263 csd-xsettings                   45   1
      625686 code                            40   2
        4557 gvfsd-trash                     36   1
        4473 cinnamon                        24   1
        4734 nemo-desktop                     9   1
      625585 code                             7   2
        5623 firefox                          7   1
        4807 gnome-terminal-server            7   1
        4261 csd-color                        5   2
        4146 systemd                          4   3
        4255 csd-automount                    4   1
        4269 csd-sound                        4   1
        4317 csd-power                        4   1
      625626 code                             3   1
        4158 pulseaudio                       2   2
        4551 evolution-source-registry        2   1
        4205 dbus-daemon                      2   1
        4448 goa-identity-service             1   1
        4571 evolution-calendar-factory       1   1
        4586 evolution-addressbook-factory    1   1
        4421 goa-daemon                       1   1
        4742 python3.8                        1   1
        4382 gvfs-afc-volume-monitor          1   1
        4351 gvfs-udisks2-volume-monitor      1   1
        4286 csd-housekeeping                 1   1
        4282 dbus-daemon                      1   1
      625685 code                             1   1
        4260 csd-background                   1   1
------------------------------------------------------------------------------
Total inotify Watches:   8189
Total inotify Instances: 35
------------------------------------------------------------------------------

If it still reproduces, jump to the next chapter.

???

@bpasero
Copy link
Member

bpasero commented May 24, 2023

The glob pattern needs to have trailing ** to match. Can you use **/node_modules/*/** for the node modules one?

@jelmd
Copy link
Author

jelmd commented May 24, 2023

Well, not sure what kind of glob pattern this is, but tried as suggested with and w/o --disable-extensions: no change, still ~8K watches in use. Attaching a file, which shows all watches - perhaps it helps to ring some bells?

zless -R inotify-watches.out.gz

or gunzip -c inotify-watches.out.gz|less -R

@bpasero
Copy link
Member

bpasero commented May 25, 2023

This only happens with TypeScript project and node_modules folder right?

@jelmd
Copy link
Author

jelmd commented May 25, 2023

Not really. I just mkdir foobar; cp -a nextjs_app/node_modules foobar/modules; added the following lines to ~/.config/Code/User/settings.json::files.watcherExclude

        "**/modules": true,
        "**/modules/**": true,
        "**/modules/*/**": true,

and cd foobar; code .

Output of inotify-info after opening a file e.g. prisma in modules/.bin/:

     1510277 code                           5942   1
     1510125 code                             7   2
     1510233 code                             5   2
     1510167 code                             3   1
     1510232 code                             1   1

So I would say no.

@bpasero
Copy link
Member

bpasero commented May 25, 2023

Ok just to confirm this is coming from our watcher, can you configure files.watcherExclude to be **? This is a hint to entirely disable any recursive file watching in VS Code. Curious if that brings the number down.

@jelmd
Copy link
Author

jelmd commented May 25, 2023

Does not work: settings.json

BTW: if I close all tabs (editors) stop code and start it again, I get

     1685869 code                             7   1
     1685778 code                             7   2
     1685819 code                             3   1
     1685868 code                             1   1

As soon as I open a file it goes up:

     1686650 code                           10109   1
     1685869 code                             7   1
     1685778 code                             7   2
     1685819 code                             3   1
     1685868 code                             1   1

@jelmd
Copy link
Author

jelmd commented May 25, 2023

For me it looks like the pattern gets ignored for all package.json as well as all directories in the CWD.

@bpasero
Copy link
Member

bpasero commented May 26, 2023

Ok that is a good finding, so which file do you open specifically that results in the watch count to increase? Are you opening package.json or any file and it goes up?

@jelmd
Copy link
Author

jelmd commented May 26, 2023

Tried with https://github.com/KaterinaLupacheva/nextjs-dashboard-layout.git to check, whether it happens on other projects as well: yepp. It seems, that watches explode as soon as a *.js or *.tsx? file gets opened. Stays at ~50 watches, if something else like *.json or .gitignore, LICENSE, etc. gets opened (using the same settings.json posted above).

@bpasero bpasero assigned mjbvz and unassigned bpasero May 26, 2023
@bpasero bpasero added typescript Typescript support issues and removed info-needed Issue requires more information from poster labels May 26, 2023
@bpasero
Copy link
Member

bpasero commented May 26, 2023

Thanks, this sounds like the typescript extension is installing watchers, ignoring our setting.

@bpasero bpasero changed the title files.watcherExclude is buggy as hell - does not work for directories TypeScript installs file watchers, ignoring files.watcherExclude setting May 26, 2023
@bpasero bpasero added bug Issue identified by VS Code Team member as probable bug file-watcher File watcher labels May 26, 2023
@jelmd
Copy link
Author

jelmd commented Jun 23, 2023

Anybody working on this nasty thing?

@mjbvz
Copy link
Collaborator

mjbvz commented Dec 14, 2023

Falls under #193848

@mjbvz mjbvz closed this as completed Dec 14, 2023
@mjbvz mjbvz added the *duplicate Issue identified as a duplicate of another issue(s) label Dec 14, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug *duplicate Issue identified as a duplicate of another issue(s) file-watcher File watcher typescript Typescript support issues
Projects
None yet
Development

No branches or pull requests

4 participants