-
Notifications
You must be signed in to change notification settings - Fork 63
fix(fs): cap file list and abort untracked scan to prevent session init timeout on large repos #3408
fix(fs): cap file list and abort untracked scan to prevent session init timeout on large repos #3408
Changes from all commits
d0e8db5
ec60938
5b6948c
2a3ccb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1181,15 +1181,39 @@ export async function listUntrackedFiles( | |||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| export interface ListAllFilesOptions { | ||||||||||||||||||||||||||||||||||
| maxFiles?: number; | ||||||||||||||||||||||||||||||||||
| timeoutMs?: number; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| export async function listAllFiles( | ||||||||||||||||||||||||||||||||||
| baseDir: string, | ||||||||||||||||||||||||||||||||||
| options?: CreateGitClientOptions, | ||||||||||||||||||||||||||||||||||
| options?: ListAllFilesOptions, | ||||||||||||||||||||||||||||||||||
| ): Promise<string[]> { | ||||||||||||||||||||||||||||||||||
| const [tracked, untracked] = await Promise.all([ | ||||||||||||||||||||||||||||||||||
| listFiles(baseDir, options), | ||||||||||||||||||||||||||||||||||
| listUntrackedFiles(baseDir, options), | ||||||||||||||||||||||||||||||||||
| ]); | ||||||||||||||||||||||||||||||||||
| return [...tracked, ...untracked]; | ||||||||||||||||||||||||||||||||||
| const { maxFiles, timeoutMs } = options ?? {}; | ||||||||||||||||||||||||||||||||||
| const controller = | ||||||||||||||||||||||||||||||||||
| timeoutMs !== undefined ? new AbortController() : undefined; | ||||||||||||||||||||||||||||||||||
| const timer = | ||||||||||||||||||||||||||||||||||
| controller && timeoutMs !== undefined | ||||||||||||||||||||||||||||||||||
| ? setTimeout(() => controller.abort(), timeoutMs) | ||||||||||||||||||||||||||||||||||
| : undefined; | ||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||
| const [tracked, untracked] = await Promise.all([ | ||||||||||||||||||||||||||||||||||
| listFiles(baseDir, { abortSignal: controller?.signal }).catch( | ||||||||||||||||||||||||||||||||||
| (): string[] => [], | ||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||
| listUntrackedFiles(baseDir, { abortSignal: controller?.signal }).catch( | ||||||||||||||||||||||||||||||||||
| (): string[] => [], | ||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||
| ]); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+1201
to
+1208
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
| const combined = untracked.concat(tracked); | ||||||||||||||||||||||||||||||||||
| if (maxFiles !== undefined && combined.length > maxFiles) { | ||||||||||||||||||||||||||||||||||
| combined.splice(maxFiles); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+1209
to
+1212
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a repo with at least 50k untracked generated files,
Suggested change
Comment on lines
+1209
to
+1212
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
| return combined; | ||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||
| if (timer) clearTimeout(timer); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Tracked + untracked files containing `pattern` (literal, case-insensitive). | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the 8s timer fires while both git commands are still running, the shared abort signal cancels the tracked scan as well as the untracked scan. Both catches then return empty arrays, so
listRepoFilescan cache and return an empty repo tree instead of the intended tracked-file fallback.