Skip to content

Commit

Permalink
Add back system watcher limit
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Nov 11, 2021
1 parent f1a20b3 commit 56842cd
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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();
}
}
Expand All @@ -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),
Expand Down

0 comments on commit 56842cd

Please sign in to comment.