Add back system watcher limit

This commit is contained in:
Andrew Branch
2021-11-11 14:57:15 -08:00
parent f1a20b34a2
commit 56842cd3bc
+8 -1
View File
@@ -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),