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
This commit is contained in:
Timon 2024-08-14 11:50:17 +02:00 committed by GitHub
parent 9d84906f57
commit 8de6b72ab9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;