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 {
418
418
context . lock . expiration - Date . now ( ) - this . automaticExtensionThreshold ;
419
419
420
420
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
+ }
430
433
}
431
434
} ;
432
435
@@ -452,10 +455,8 @@ export class RunLocker {
452
455
453
456
if ( ! error && newLock ) {
454
457
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 ( ) ;
459
460
} else {
460
461
if ( context . lock . expiration > Date . now ( ) ) {
461
462
// If lock hasn't expired yet, schedule a retry instead of recursing
You can’t perform that action at this time.
0 commit comments