Skip to content

Commit 56842cd

Browse files
committed
Add back system watcher limit
1 parent f1a20b3 commit 56842cd

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/compiler/sys.ts

Lines changed: 8 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,11 @@ namespace ts {
16191620
options = { persistent: true };
16201621
}
16211622
}
1623+
1624+
if (hitSystemWatcherLimit) {
1625+
sysLog(`sysLog:: ${fileOrDirectory}:: Defaulting to fsWatchFile`);
1626+
return watchPresentFileSystemEntryWithFsWatchFile();
1627+
}
16221628
try {
16231629
const presentWatcher = _fs.watch(
16241630
fileOrDirectory,
@@ -1635,6 +1641,8 @@ namespace ts {
16351641
// Catch the exception and use polling instead
16361642
// 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
16371643
// so instead of throwing error, use fs.watchFile
1644+
hitSystemWatcherLimit ||= e.code === "ENOSPC";
1645+
sysLog(`sysLog:: ${fileOrDirectory}:: Changing to fsWatchFile`);
16381646
return watchPresentFileSystemEntryWithFsWatchFile();
16391647
}
16401648
}
@@ -1656,7 +1664,6 @@ namespace ts {
16561664
* 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
16571665
*/
16581666
function watchPresentFileSystemEntryWithFsWatchFile(): FileWatcher {
1659-
sysLog(`sysLog:: ${fileOrDirectory}:: Changing to fsWatchFile`);
16601667
return watchFile(
16611668
fileOrDirectory,
16621669
createFileWatcherCallback(callback),

0 commit comments

Comments
 (0)