File tree Expand file tree Collapse file tree 1 file changed +32
-3
lines changed
Expand file tree Collapse file tree 1 file changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -27,9 +27,38 @@ export const loadConfig = async (configPath: string): Promise<SourcebotConfig> =
2727 }
2828 return response . text ( ) ;
2929 } else {
30- return readFile ( configPath , {
31- encoding : 'utf-8' ,
32- } ) ;
30+ // Retry logic for handling race conditions with mounted volumes
31+ const maxAttempts = 5 ;
32+ const retryDelayMs = 2000 ;
33+ let lastError : Error | null = null ;
34+
35+ for ( let attempt = 1 ; attempt <= maxAttempts ; attempt ++ ) {
36+ try {
37+ return await readFile ( configPath , {
38+ encoding : 'utf-8' ,
39+ } ) ;
40+ } catch ( error ) {
41+ lastError = error as Error ;
42+
43+ // Only retry on ENOENT errors (file not found)
44+ if ( ( error as NodeJS . ErrnoException ) ?. code !== 'ENOENT' ) {
45+ throw error ; // Throw immediately for non-ENOENT errors
46+ }
47+
48+ // Log warning before retry (except on the last attempt)
49+ if ( attempt < maxAttempts ) {
50+ console . warn ( `Config file not found, retrying in 2s... (Attempt ${ attempt } /${ maxAttempts } )` ) ;
51+ await new Promise ( resolve => setTimeout ( resolve , retryDelayMs ) ) ;
52+ }
53+ }
54+ }
55+
56+ // If we've exhausted all retries, throw the last ENOENT error
57+ if ( lastError ) {
58+ throw lastError ;
59+ }
60+
61+ throw new Error ( 'Failed to load config after all retry attempts' ) ;
3362 }
3463 } ) ( ) ;
3564
You can’t perform that action at this time.
0 commit comments