File tree Expand file tree Collapse file tree 1 file changed +14
-13
lines changed
internal-packages/run-engine/src/engine Expand file tree Collapse file tree 1 file changed +14
-13
lines changed Original file line number Diff line number Diff line change @@ -418,15 +418,18 @@ export class RunLocker {
418418 context . lock . expiration - Date . now ( ) - this . automaticExtensionThreshold ;
419419
420420 if ( timeUntilExtension > 0 ) {
421- context . timeout = setTimeout ( ( ) => {
422- context . extension = this . #extendLock(
423- context ,
424- duration ,
425- signal ,
426- controller ,
427- scheduleExtension
428- ) ;
429- } , timeUntilExtension ) ;
421+ // Check for cleanup immediately before scheduling to prevent race condition
422+ if ( context . timeout !== null ) {
423+ context . timeout = setTimeout ( ( ) => {
424+ context . extension = this . #extendLock(
425+ context ,
426+ duration ,
427+ signal ,
428+ controller ,
429+ scheduleExtension
430+ ) ;
431+ } , timeUntilExtension ) ;
432+ }
430433 }
431434 } ;
432435
@@ -452,10 +455,8 @@ export class RunLocker {
452455
453456 if ( ! error && newLock ) {
454457 context . lock = newLock ;
455- // Only schedule next extension if we haven't been cleaned up
456- if ( context . timeout !== null ) {
457- scheduleNext ( ) ;
458- }
458+ // Schedule next extension (cleanup check is now inside scheduleNext)
459+ scheduleNext ( ) ;
459460 } else {
460461 if ( context . lock . expiration > Date . now ( ) ) {
461462 // If lock hasn't expired yet, schedule a retry instead of recursing
You can’t perform that action at this time.
0 commit comments