@@ -341,6 +341,13 @@ async function execRipgrep(rgPath: string, args: string[], limit: number): Promi
341341 let output = ""
342342 let results : string [ ] = [ ]
343343
344+ // Set timeout to avoid hanging
345+ const timeoutId = setTimeout ( ( ) => {
346+ rgProcess . kill ( )
347+ console . warn ( "ripgrep timed out, returning partial results" )
348+ resolve ( results . slice ( 0 , limit ) )
349+ } , 10_000 )
350+
344351 // Process stdout data as it comes in
345352 rgProcess . stdout . on ( "data" , ( data ) => {
346353 output += data . toString ( )
@@ -349,6 +356,7 @@ async function execRipgrep(rgPath: string, args: string[], limit: number): Promi
349356 // Kill the process if we've reached the limit
350357 if ( results . length >= limit ) {
351358 rgProcess . kill ( )
359+ clearTimeout ( timeoutId ) // Clear the timeout when we kill the process due to reaching the limit
352360 }
353361 } )
354362
@@ -357,13 +365,6 @@ async function execRipgrep(rgPath: string, args: string[], limit: number): Promi
357365 console . error ( `ripgrep stderr: ${ data } ` )
358366 } )
359367
360- // Set timeout to avoid hanging
361- const timeoutId = setTimeout ( ( ) => {
362- rgProcess . kill ( )
363- console . warn ( "ripgrep timed out, returning partial results" )
364- resolve ( results . slice ( 0 , limit ) )
365- } , 10_000 )
366-
367368 // Handle process completion
368369 rgProcess . on ( "close" , ( code ) => {
369370 // Clear the timeout to avoid memory leaks
0 commit comments