language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Prisma VSCode Plugin 2.27.0 memory leak/too many processes

Open m3ki opened this issue 4 years ago • 2 comments

Bug description

There seems to be some sort of issue with v2.27.0 of vscode plugin where if it is enabled in VScode then when running yarn dev terminal will eventually start throwing errors like below.

I believe it has something to do with prisma plugin watching files for changes.

Reverting to v2.26.0 resolves the issue.

Error 1

zsh: fork failed: resource temporarily unavailable

Error 2

yarn dev
yarn run v1.22.10
$ next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Loaded env from /Users/user/Development/rc/ffs-dev/.env
info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: spawn /usr/local/bin/node EAGAIN
    at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: -35,
  code: 'EAGAIN',
  syscall: 'spawn /usr/local/bin/node',
  path: '/usr/local/bin/node',
  spawnargs: [
    '/Users/user/Development/rc/ffs-dev/node_modules/jest-worker/build/workers/processChild.js'
  ]
}
error Command failed with exit code 1.

How to reproduce

Steps to reproduce the behavior:

  1. Open VScode
  2. make sure prisma 2.27.0 vscode plugin is installed
  3. in terminal iterm2 or any other, run project with yarn dev
  4. Observer errors yarn dev will crash
  5. try to run yarn dev again notice the following error
zsh: fork failed: resource temporarily unavailable
  1. try running yarn dev again Observer the error
eady - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Loaded env from /Users/user/Development/rc/ffs-dev/.env
info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: spawn /usr/local/bin/node EAGAIN
    at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: -35,
  code: 'EAGAIN',
  syscall: 'spawn /usr/local/bin/node',
  path: '/usr/local/bin/node',
  spawnargs: [
    '/Users/user/Development/rc/ffs-dev/node_modules/jest-worker/build/workers/processChild.js'
  ]
}
error Command failed with exit code 1.
  1. Kill vscode or install v2.26.0
  2. Notice that you can now run yarn dev and no issues are happening anymore

Expected behavior

Prisma information

Environment & setup

  • OS: OSX Big Sur
  • Editor:
Version: 1.58.2
Commit: c3f126316369cd610563c75b1b1725e0679adfb3
Date: 2021-07-14T22:09:06.581Z
Electron: 12.0.13
Chrome: 89.0.4389.128
Node.js: 14.16.0
V8: 8.9.255.25-electron.0
OS: Darwin x64 20.5.0
  • Extension version:v2.27.0
  • Vscode has no other extensions installed

m3ki avatar Jul 20 '21 03:07 m3ki

Since version 3.8.0 of the Prisma VS Code extension released yesterday there is now a way to disable the File Watcher.

It's implemented as a (default = true) boolean in the settings Screen Shot 2021-12-21 at 13 04 46 Screen Shot 2021-12-21 at 13 04 14

And can be enabled/disabled from the command palette UI like this Screen Shot 2021-12-21 at 13 03 51

Could you check

  1. That your problem still exists with version 3.8.0 or newer
  2. Run the Prisma: Disable the File Watcher functionality for Prisma Client command
  3. Did that solve the problem?
    • If no, try to reload VS Code.
    • If yes please let us know, it will be helpful for us.

Jolg42 avatar Jan 12 '22 13:01 Jolg42

Thank you will try!

m3ki avatar Apr 22 '22 18:04 m3ki

Hi! @m3ki

I created a PR to fix the file watcher issue, I'm happy to report that on my computer (macOS m1) it's now fixed. (CPU goes from ~100% previously to 0%)

Could you confirm it's also fixed for you as well?

Follow these instructions

First, confirm that the CPU usage is high using the Prisma extension from the VS Code marketplace

  • Open your project using Prisma
  • If you disabled the Prisma File Watcher functionality, enable it again from the command palette: Screenshot 2022-09-08 at 22 09 12
  • Open the schema.prisma file from your project
  • Use "Open Process Explorer" from VS Code' menu or open the OS Activity monitor Screenshot 2022-09-08 at 22 07 22
  • Note / screenshot the CPU usage for the extension host above the Prisma extension process for the explorer or for the Activity Monitor, the Code Helper (Renderer) value and share it at the end

Second, confirm that with the new extension the CPU usage is low using a special build from my PR

Note: only the file watcher logic was changed.

  • Uninstall any Prisma extension installed (uninstall is preferred as only disabling might interfere in some ways)
  • Download https://github.com/prisma/language-tools/blob/artifacts/pull-request-artifacts/pr1243-prisma.vsix?raw=true
  • Click "Install from VSIX" from this button (screenshot) or command palette and select the pr1243-prisma.vsix file Screenshot 2022-09-08 at 22 05 33
  • Restart the VS Code application
  • Open the schema.prisma file from your project
  • Use "Open Process Explorer" from VS Code' menu or open the OS Activity monitor Screenshot 2022-09-08 at 22 07 22
  • Note / screenshot the CPU usage for the extension host above the Prisma extension process for the explorer or for the Activity Monitor, the Code Helper (Renderer) value and share it at the end

Third, if you have a TypeScript project, confirm that the file watcher works and that the types are refreshed

  • Open a TypeScript file from your project where you have Prisma Client queries like await prisma.user.findMany()
  • Open the schema.prisma file from your project
  • Both should have no errors
  • Edit the schema.prisma file and delete all the models (only keep the datasource & generator blocks)
  • Run npx prisma generate
  • In your TypeScript file, you should now instantly see a Type Error that should look like the following Screenshot 2022-09-08 at 22 20 12
  • Undo the changes in your schema.prisma
  • Run npx prisma generate
  • The Type Error(s) in the TypeScript file should be gone now

Please share something like the following: I tested on ... (macOS m1, Windows, Linux....)

  1. Current extension: screenshot showing ~91% CPU (Note: CPU is only reported on the aggregated top line for some reason) current_filewatcher_enabled_cpu_at_100ish
  2. Using pr1243-prisma.vsix, screenshot after showing ~0% CPU usage 🎊 new_filewatcher_enabled_cpu_at_0
  3. The typings were updated successfully after npx prisma generate, a Type Error was visible ✅

Thank you in advance 💚 Note: I'm waiting for some feedback before we switch to this new low CPU file watcher in a stable release on VS Code marketplace.

Jolg42 avatar Sep 08 '22 20:09 Jolg42

Will try this weekend

m3ki avatar Sep 08 '22 23:09 m3ki

The fix is now in the latest 4.4.0 version on the marketplace https://marketplace.visualstudio.com/items?itemName=Prisma.prisma 🎊

For those who disabled the File Watcher functionality, you can enable it again.

Jolg42 avatar Sep 28 '22 08:09 Jolg42