fix(server): avoid recursive checkout diff watches on linux
This commit is contained in:
@@ -3934,17 +3934,17 @@ export class Session {
|
|||||||
latestFingerprint: null,
|
latestFingerprint: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const watchPaths = new Set<string>([cwd]);
|
const repoWatchPath = watchRoot ?? cwd;
|
||||||
if (watchRoot) {
|
const watchPaths = new Set<string>([repoWatchPath]);
|
||||||
watchPaths.add(watchRoot);
|
|
||||||
}
|
|
||||||
const gitDir = await this.resolveCheckoutGitDir(cwd);
|
const gitDir = await this.resolveCheckoutGitDir(cwd);
|
||||||
if (gitDir) {
|
if (gitDir) {
|
||||||
watchPaths.add(gitDir);
|
watchPaths.add(gitDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
let hasWatchRootCoverage = false;
|
let hasRecursiveRepoCoverage = false;
|
||||||
|
const allowRecursiveRepoWatch = process.platform !== "linux";
|
||||||
for (const watchPath of watchPaths) {
|
for (const watchPath of watchPaths) {
|
||||||
|
const shouldTryRecursive = watchPath === repoWatchPath && allowRecursiveRepoWatch;
|
||||||
const createWatcher = (recursive: boolean): FSWatcher =>
|
const createWatcher = (recursive: boolean): FSWatcher =>
|
||||||
watch(
|
watch(
|
||||||
watchPath,
|
watchPath,
|
||||||
@@ -3955,18 +3955,31 @@ export class Session {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let watcher: FSWatcher | null = null;
|
let watcher: FSWatcher | null = null;
|
||||||
|
let watcherIsRecursive = false;
|
||||||
try {
|
try {
|
||||||
watcher = createWatcher(true);
|
if (shouldTryRecursive) {
|
||||||
} catch (error) {
|
watcher = createWatcher(true);
|
||||||
try {
|
watcherIsRecursive = true;
|
||||||
|
} else {
|
||||||
watcher = createWatcher(false);
|
watcher = createWatcher(false);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (shouldTryRecursive) {
|
||||||
|
try {
|
||||||
|
watcher = createWatcher(false);
|
||||||
|
this.sessionLogger.warn(
|
||||||
|
{ err: error, watchPath, cwd, compare },
|
||||||
|
"Checkout diff recursive watch unavailable; using non-recursive fallback"
|
||||||
|
);
|
||||||
|
} catch (fallbackError) {
|
||||||
|
this.sessionLogger.warn(
|
||||||
|
{ err: fallbackError, watchPath, cwd, compare },
|
||||||
|
"Failed to start checkout diff watcher"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
this.sessionLogger.warn(
|
this.sessionLogger.warn(
|
||||||
{ err: error, watchPath, cwd, compare },
|
{ err: error, watchPath, cwd, compare },
|
||||||
"Checkout diff recursive watch unavailable; using non-recursive fallback"
|
|
||||||
);
|
|
||||||
} catch (fallbackError) {
|
|
||||||
this.sessionLogger.warn(
|
|
||||||
{ err: fallbackError, watchPath, cwd, compare },
|
|
||||||
"Failed to start checkout diff watcher"
|
"Failed to start checkout diff watcher"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -3983,12 +3996,12 @@ export class Session {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
target.watchers.push(watcher);
|
target.watchers.push(watcher);
|
||||||
if (watchRoot && watchPath === watchRoot) {
|
if (watchPath === repoWatchPath && watcherIsRecursive) {
|
||||||
hasWatchRootCoverage = true;
|
hasRecursiveRepoCoverage = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const missingRepoCoverage = Boolean(watchRoot) && !hasWatchRootCoverage;
|
const missingRepoCoverage = !hasRecursiveRepoCoverage;
|
||||||
if (target.watchers.length === 0 || missingRepoCoverage) {
|
if (target.watchers.length === 0 || missingRepoCoverage) {
|
||||||
target.fallbackRefreshInterval = setInterval(() => {
|
target.fallbackRefreshInterval = setInterval(() => {
|
||||||
this.scheduleCheckoutDiffTargetRefresh(target);
|
this.scheduleCheckoutDiffTargetRefresh(target);
|
||||||
@@ -4001,7 +4014,7 @@ export class Session {
|
|||||||
reason:
|
reason:
|
||||||
target.watchers.length === 0
|
target.watchers.length === 0
|
||||||
? "no_watchers"
|
? "no_watchers"
|
||||||
: "missing_repo_root_coverage",
|
: "missing_recursive_repo_root_coverage",
|
||||||
},
|
},
|
||||||
"Checkout diff watchers unavailable; using timed refresh fallback"
|
"Checkout diff watchers unavailable; using timed refresh fallback"
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user