From 8de6b72ab96871f4eaa02dd564b73fd114efab15 Mon Sep 17 00:00:00 2001 From: Timon <39559178+Its-treason@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:50:17 +0200 Subject: [PATCH] Fix/enospc (#2789) * fix: Handle ENOSPC error from chokidar Now listens to the error event to check if "ENOSPC" occurrs. The watcher will then automaticly restart in polling mode, so that the user still sees his reqeusts / collections. Fixes: https://github.com/usebruno/bruno/issues/1877 * Add more code comments, add !forcePolling to prevent endless loops and update error message * fix: Also listen for EMFILE for too many watched files --- packages/bruno-electron/src/app/watcher.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/bruno-electron/src/app/watcher.js b/packages/bruno-electron/src/app/watcher.js index 8a434fa64..589cd29d8 100644 --- a/packages/bruno-electron/src/app/watcher.js +++ b/packages/bruno-electron/src/app/watcher.js @@ -464,9 +464,10 @@ class Watcher { .on('unlink', (pathname) => unlink(win, pathname, collectionUid, watchPath)) .on('unlinkDir', (pathname) => unlinkDir(win, pathname, collectionUid, watchPath)) .on('error', (error) => { + // `EMFILE` is an error code thrown when to many files are watched at the same time see: https://github.com/usebruno/bruno/issues/627 // `ENOSPC` stands for "Error No space" but is also thrown if the file watcher limit is reached. // To prevent loops `!forcePolling` is checked. - if (error.code === 'ENOSPC' && !startedNewWatcher && !forcePolling) { + if ((error.code === 'ENOSPC' || error.code === 'EMFILE') && !startedNewWatcher && !forcePolling) { // This callback is called for every file the watcher is trying to watch. To prevent a spam of messages and // Multiple watcher being started `startedNewWatcher` is set to prevent this. startedNewWatcher = true;