@@ -24,6 +24,7 @@ const E2E_DIRECTORY = './e2e';
2424let needsCleanup = false ;
2525let isCleaningUp = false ;
2626let currentTestProcess = null ;
27+ let isShuttingDown = false ;
2728
2829/**
2930 * Main execution function
@@ -318,26 +319,37 @@ async function cleanup() {
318319 */
319320async function handleGracefulShutdown ( signal ) {
320321 // Prevent multiple signal handlers from running
321- if ( isCleaningUp ) {
322- console . log ( `\n⏳ Already cleaning up , ignoring ${ signal } ...` ) ;
322+ if ( isShuttingDown ) {
323+ console . log ( `\n⏳ Already shutting down , ignoring ${ signal } ...` ) ;
323324 return ;
324325 }
325326
327+ isShuttingDown = true ;
326328 console . log ( `\n⚠️ Received ${ signal } . Performing cleanup before exit...` ) ;
327329
328330 // Kill the test process if it's running
329331 if ( currentTestProcess && ! currentTestProcess . killed ) {
330332 console . log ( '🛑 Terminating running test process...' ) ;
331- currentTestProcess . kill ( 'SIGTERM' ) ;
332- // Give it a moment to terminate gracefully
333- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
334- if ( ! currentTestProcess . killed ) {
335- currentTestProcess . kill ( 'SIGKILL' ) ;
333+ try {
334+ currentTestProcess . kill ( 'SIGTERM' ) ;
335+ // Give it a moment to terminate gracefully
336+ await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) ) ;
337+ if ( ! currentTestProcess . killed ) {
338+ currentTestProcess . kill ( 'SIGKILL' ) ;
339+ }
340+ } catch ( error ) {
341+ console . log ( '⚠️ Error terminating test process:' , error . message ) ;
336342 }
337343 }
338344
345+ // Only cleanup if we haven't already started
339346 if ( needsCleanup && ! isCleaningUp ) {
340347 try {
348+ // Temporarily ignore signals during cleanup to prevent interruption
349+ process . removeAllListeners ( 'SIGINT' ) ;
350+ process . removeAllListeners ( 'SIGTERM' ) ;
351+ process . removeAllListeners ( 'SIGHUP' ) ;
352+
341353 await cleanup ( ) ;
342354 } catch ( cleanupError ) {
343355 console . error ( '❌ Cleanup failed during shutdown:' , cleanupError . message ) ;
0 commit comments