Skip to content

TypeScript file Watcher consuming over 5k watchers #46351

Closed

Description

@oof2win2

Issue Type: Bug

Since the latest update of Insiders, it has begun to use a new file watcher (from what I see here and the new Files: Legacy Watcher setting). My issue however is that this is not working and file watchers are still being consumed.

This is the output of inotify-consumers, npm i and then running inotify-consumers again. To note, node_modules/ was removed prior to the first consumer check.

oof2win2@koelkast:/opt/factorio/AwF-Bot-Test$ rm -rf node_modules/
oof2win2@koelkast:/opt/factorio/AwF-Bot-Test$ ~/cmds/inotify-consumers 

   INOTIFY
   WATCHER
    COUNT     PID     CMD
----------------------------------------
     235  2812552  /home/oof2win2/.vscode-server-insiders/bin/284e0db6c4cac1e557a43cd6691babdaafc2e1a9/node --max-old-space-size=3072 /home
      96  2812533  /home/oof2win2/.vscode-server-insiders/bin/284e0db6c4cac1e557a43cd6691babdaafc2e1a9/node /home/oof2win2/.vscode-server-i
       4    46817  /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
       4  2812522  /home/oof2win2/.vscode-server-insiders/bin/284e0db6c4cac1e557a43cd6691babdaafc2e1a9/node /home/oof2win2/.vscode-server-i
       4  2812450  /home/oof2win2/.vscode-server-insiders/bin/284e0db6c4cac1e557a43cd6691babdaafc2e1a9/node /home/oof2win2/.vscode-server-i
       2    46787  /lib/systemd/systemd --user
       1    46787  /lib/systemd/systemd --user
       1    46787  /lib/systemd/systemd --user
       0  2812582  /home/oof2win2/.vscode-server-insiders/bin/284e0db6c4cac1e557a43cd6691babdaafc2e1a9/node /home/oof2win2/.vscode-server-i

     347     WATCHERS TOTAL COUNT
oof2win2@koelkast:/opt/factorio/AwF-Bot-Test$ npm i

npm installation here

oof2win2@koelkast:/opt/factorio/AwF-Bot-Test$ ~/cmds/inotify-consumers 

   INOTIFY
   WATCHER
    COUNT     PID     CMD
----------------------------------------
    2540  2812552  /home/oof2win2/.vscode-server-insiders/bin/284e0db6c4cac1e557a43cd6691babdaafc2e1a9/node --max-old-space-size=3072 /home
    2305  2812582  /home/oof2win2/.vscode-server-insiders/bin/284e0db6c4cac1e557a43cd6691babdaafc2e1a9/node /home/oof2win2/.vscode-server-i
      96  2812533  /home/oof2win2/.vscode-server-insiders/bin/284e0db6c4cac1e557a43cd6691babdaafc2e1a9/node /home/oof2win2/.vscode-server-i
       4    46817  /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
       4  2812522  /home/oof2win2/.vscode-server-insiders/bin/284e0db6c4cac1e557a43cd6691babdaafc2e1a9/node /home/oof2win2/.vscode-server-i
       4  2812450  /home/oof2win2/.vscode-server-insiders/bin/284e0db6c4cac1e557a43cd6691babdaafc2e1a9/node /home/oof2win2/.vscode-server-i
       2    46787  /lib/systemd/systemd --user
       1    46787  /lib/systemd/systemd --user
       1    46787  /lib/systemd/systemd --user

    4957     WATCHERS TOTAL COUNT
oof2win2@koelkast:/opt/factorio/AwF-Bot-Test$ 

Here are my settings.json. Used this as just "**/node_modules/**: true, which is included, did not work.

{
  "files.watcherExclude": {
    "**": true,
    "**/**": true
  }
}

VS Code version: Code - Insiders 1.62.0-insider (284e0db, 2021-10-12T05:44:21.888Z)
OS version: Darwin x64 20.5.0
Restricted Mode: No
Remote OS version: Linux x64 5.4.0-80-generic

System Info
Item Value
CPUs Intel(R) Core(TM) i5-1030NG7 CPU @ 1.10GHz (8 x 1100)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 3, 3, 3
Memory (System) 8.00GB (0.11GB free)
Process Argv --crash-reporter-id 11b22232-fe4c-4ed0-a0a1-d5910ebb956b
Screen Reader no
VM 0%
Item Value
Remote SSH: awf
OS Linux x64 5.4.0-80-generic
CPUs Intel(R) Core(TM) i7-6800K CPU @ 3.40GHz (12 x 1200)
Memory (System) 31.27GB (4.74GB free)
VM 0%
Extensions (4)
Extension Author (truncated) Version
remote-ssh ms- 0.65.8
remote-ssh-edit ms- 0.65.8
todo-tree Gru 0.0.214
html-preview-vscode tht 0.2.5
A/B Experiments
vsliv695:30137379
vsins829:30139715
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
pythonvspyt602:30291494
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyt639:30291487
pythontb:30258533
pythonvspyt551:30291412
pythonptprofiler:30281269
vsdfh931cf:30280410
vshan820:30294714
pythondataviewer:30285072
pythonvsuse255:30319630
vscod805:30301674
pythonvspyt200:30323110
vsccppwt:30377800
pythonvssor306:30340298
bridge0708:30335490
pygetstartedt2:30353727
bridge0723:30353136
pythonrunftest32:30365365
pythonf5test824:30361779
javagetstartedt:30350119
pythonvspyt187:30365360
pydsgst2:30361790
vsqsis400:30374798
vsaa593cf:30376535

Activity

  1. bpasero commented on Oct 13, 2021

    @bpasero

    oof2win2 (@oof2win2) thanks for testing this. As a first question, can you run code-insiders --verbose, open a folder and then in devtools see which file watcher is being used? You should see something like this:

    image

    It would also give a hint what excludes are actually being used.

  2. oof2win2 commented on Oct 13, 2021

    @oof2win2
    Author

    No watcher seems to be used?

    Screenshot 2021-10-13 at 8 09 58

    When I open a normal window (non-SSH), it shows me Parcel is being used with this output

    Screenshot 2021-10-13 at 8 11 43

  3. bpasero commented on Oct 13, 2021

    @bpasero

    oof2win2 (@oof2win2) oh, so this is an issue you see with connecting remotely via SSH to a Linux remote? If that is the case you will have to change the log level via this command:

    image

    To "trace" and then see the output via "Log (Server)" in output panel.

  4. oof2win2 commented on Oct 13, 2021

    @oof2win2
    Author

    Ah, then the output is this:

    [2021-10-13 06:50:20.658] [remoteagent] [debug] [File Watcher (parcel)] Request to start watching: /opt/factorio/AwF-Bot-Test (excludes: **/.git/objects/**,**/.git/subtree-cache/**,**/node_modules/*/**,**/.hg/store/**,**,**/**,/home/oof2win2/.vscode-server-insiders/extensions/**),/opt/factorio/servers/test/scenarios/AwF-Scenario (excludes: **/.git/objects/**,**/.git/subtree-cache/**,**/node_modules/*/**,**/.hg/store/**,**,**/**,/home/oof2win2/.vscode-server-insiders/extensions/**)
    [2021-10-13 06:50:20.658] [remoteagent] [debug] [File Watcher (parcel)] Request to stop watching: 
    [2021-10-13 06:50:20.659] [remoteagent] [debug] [File Watcher (parcel)] Started watching: '/opt/factorio/AwF-Bot-Test' with backend 'inotify' and native excludes '/opt/factorio/AwF-Bot-Test/.git/objects, /opt/factorio/AwF-Bot-Test/.git/subtree-cache, /opt/factorio/AwF-Bot-Test/node_modules, /opt/factorio/AwF-Bot-Test/.hg/store, /opt/factorio/AwF-Bot-Test'
    [2021-10-13 06:50:20.659] [remoteagent] [debug] [File Watcher (parcel)] Started watching: '/opt/factorio/servers/test/scenarios/AwF-Scenario' with backend 'inotify' and native excludes '/opt/factorio/servers/test/scenarios/AwF-Scenario/.git/objects, /opt/factorio/servers/test/scenarios/AwF-Scenario/.git/subtree-cache, /opt/factorio/servers/test/scenarios/AwF-Scenario/node_modules, /opt/factorio/servers/test/scenarios/AwF-Scenario/.hg/store, /opt/factorio/servers/test/scenarios/AwF-Scenario'
    
  5. bpasero commented on Oct 13, 2021

    @bpasero

    So it looks like 2 file watchers are installed (with parcel) and /opt/factorio/AwF-Bot-Test/node_modules and /opt/factorio/servers/test/scenarios/AwF-Scenario/node_modules are excluded. Do you think that does not work?

  6. oof2win2 commented on Oct 13, 2021

    @oof2win2
    Author

    Yeah, I think that doesn't work. The excludes have ** and **/** in them, so everything should be excluded, right?

  7. oof2win2 commented on Oct 13, 2021

    @oof2win2
    Author

    Nevermind, seems that the node_modules exclusion does work. It was **/.git/** that reduced the watchers to just 70. Still think that ** and **/** should work though Seems I was wrong there. The file watchers don't spawn until I open a file.

  8. bpasero commented on Oct 13, 2021

    @bpasero

    Yes, a files.watcherExclude of ** will essentially ignore the workspace folder and you should not see file handles being used as a result. The log message should confirm that if you look for "native excludes", because those are the paths we send to parcel for exclusion.

    That said, it is possible that something else is consuming file handles that is not the file watcher maybe?

  9. oof2win2 commented on Oct 13, 2021

    @oof2win2
    Author

    Like a different app or service? Not sure what it would be. Without any extensions (except SSH), the file watchers stay. Disconnecting from the remote frees it of any watchers from the VSCode server executable.

  10. bpasero commented on Oct 13, 2021

    @bpasero

    oof2win2 (@oof2win2) can you validate this again without opening any files? the file watcher will start independent from individual files opening as long as you open the folder /opt/factorio/AwF-Bot-Test as workspace.

  11. oof2win2 commented on Oct 13, 2021

    @oof2win2
    Author

    With no files open, the system total of watchers is 70. The workspace is open.

  12. bpasero commented on Oct 13, 2021

    @bpasero

    oof2win2 (@oof2win2) ok that confirms to me that something else is starting to install watchers. Is it possible that the files you open start an extension (such as "TypeScript") and they install further file watchers?

    To proof that point, you could try to disable all extensions (on the server as well as client).

  13. oof2win2 commented on Oct 13, 2021

    @oof2win2
    Author

    The @enabled tag shows only Remote - SSH and Remote - SSH: Editing Configuration Files. Since I am however opening a TS file, I created a new file - testing.malloc which shouldn't run any built-in extensions. It showed only the 70 file watchers across the system. JSON files are the same. JS files however start the extra file watchers. With no extensions, could it be the integrated JS/TS language support?

  14. 11 remaining items

  15. bpasero commented on Oct 15, 2021

    @bpasero

    but this sounds expected for us

    Why can you not rely on the file events VS Code sends for a workspace to your extension?

  16. oof2win2 commented on Oct 15, 2021

    @oof2win2
    Author

    Looked at the log just now and it seems that TS finds all typescript stuff scross the system and then watches it just if something happens? I agree with Benjamin Pasero (@bpasero) that TS should listen to VSCode's ignores and not watch files if they are in the ignore path.

  17. added
    Needs Investigation
    and removed
    Needs More Info
    on Oct 20, 2021
  18. bpasero commented on Mar 30, 2022

    @bpasero

    Fyi microsoft/vscode#146066 makes the createFileSystemWatcher API more powerful: if you watch inside the workspace and your watcher is not recursive, the files.watcherExclude setting will not apply to you. This will help you watching inside node_modules folder because that folder is ignored by default via settings.

    My understanding is that TypeScript does not require recursive watching because you only need to watch the @types folder for changes and that would work with a flat watcher 🚀

  19. sheetalkamat commented on May 9, 2022

    @sheetalkamat
    Member

    If anyone wants to do custom watching, we do allow users to exclude directories and folders from watches.. So users can opt to disable watching and refresh the state as they like but our watching tries to cater for various types of scale and uses and also os variants.

  20. added
    Working as Intended
    and removed
    Needs Investigation
    on May 9, 2022
  21. typescript-bot commented on May 12, 2022

    @typescript-bot
    Contributor

    This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  22. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Working as Intended

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions