From 56842cd3bc42362576befc4124887b89e7006515 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 11 Nov 2021 14:57:15 -0800 Subject: [PATCH] Add back system watcher limit --- src/compiler/sys.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index da38d389f212f..b41e89e991567 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -1266,6 +1266,7 @@ namespace ts { let activeSession: import("inspector").Session | "stopping" | undefined; let profilePath = "./profile.cpuprofile"; + let hitSystemWatcherLimit = false; const Buffer: { new (input: string, encoding?: string): any; @@ -1619,6 +1620,11 @@ namespace ts { options = { persistent: true }; } } + + if (hitSystemWatcherLimit) { + sysLog(`sysLog:: ${fileOrDirectory}:: Defaulting to fsWatchFile`); + return watchPresentFileSystemEntryWithFsWatchFile(); + } try { const presentWatcher = _fs.watch( fileOrDirectory, @@ -1635,6 +1641,8 @@ namespace ts { // Catch the exception and use polling instead // Eg. on linux the number of watches are limited and one could easily exhaust watches and the exception ENOSPC is thrown when creating watcher at that point // so instead of throwing error, use fs.watchFile + hitSystemWatcherLimit ||= e.code === "ENOSPC"; + sysLog(`sysLog:: ${fileOrDirectory}:: Changing to fsWatchFile`); return watchPresentFileSystemEntryWithFsWatchFile(); } } @@ -1656,7 +1664,6 @@ namespace ts { * Eg. on linux the number of watches are limited and one could easily exhaust watches and the exception ENOSPC is thrown when creating watcher at that point */ function watchPresentFileSystemEntryWithFsWatchFile(): FileWatcher { - sysLog(`sysLog:: ${fileOrDirectory}:: Changing to fsWatchFile`); return watchFile( fileOrDirectory, createFileWatcherCallback(callback),