Skip to content

Commit 7091edc

Browse files
committed
Stop trying to add file watchers after hitting the system limit
1 parent a01c8aa commit 7091edc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/compiler/sys.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,7 @@ namespace ts {
12661266
let activeSession: import("inspector").Session | "stopping" | undefined;
12671267
let profilePath = "./profile.cpuprofile";
12681268

1269+
let hitSystemWatcherLimit = false;
12691270

12701271
const Buffer: {
12711272
new (input: string, encoding?: string): any;
@@ -1619,6 +1620,12 @@ namespace ts {
16191620
options = { persistent: true };
16201621
}
16211622
}
1623+
1624+
if (hitSystemWatcherLimit) {
1625+
sysLog(`sysLog:: ${fileOrDirectory}:: Defaulting to fsWatchFile`);
1626+
return watchPresentFileSystemEntryWithFsWatchFile();
1627+
}
1628+
16221629
try {
16231630
const presentWatcher = _fs.watch(
16241631
fileOrDirectory,
@@ -1635,6 +1642,8 @@ namespace ts {
16351642
// Catch the exception and use polling instead
16361643
// 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
16371644
// so instead of throwing error, use fs.watchFile
1645+
hitSystemWatcherLimit ||= e.code === "ENOSPC";
1646+
sysLog(`sysLog:: ${fileOrDirectory}:: Changing to fsWatchFile`);
16381647
return watchPresentFileSystemEntryWithFsWatchFile();
16391648
}
16401649
}
@@ -1656,7 +1665,6 @@ namespace ts {
16561665
* 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
16571666
*/
16581667
function watchPresentFileSystemEntryWithFsWatchFile(): FileWatcher {
1659-
sysLog(`sysLog:: ${fileOrDirectory}:: Changing to fsWatchFile`);
16601668
return watchFile(
16611669
fileOrDirectory,
16621670
createFileWatcherCallback(callback),

0 commit comments

Comments
 (0)