Skip to content

Commit 1293d43

Browse files
committed
Handle undefined lock edge case
1 parent 2894808 commit 1293d43

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

internal-packages/run-engine/src/engine/locking.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export class RunLocker {
213213
let totalWaitTime = 0;
214214

215215
// Retry the lock acquisition with exponential backoff
216-
let lock: redlock.Lock;
216+
let lock: redlock.Lock | undefined;
217217
let lastError: Error | undefined;
218218

219219
for (let attempt = 0; attempt <= maxRetries; attempt++) {
@@ -315,6 +315,23 @@ export class RunLocker {
315315
throw lastError;
316316
}
317317

318+
// Safety guard: ensure lock was successfully acquired
319+
if (!lock) {
320+
this.logger.error("[RunLocker] Lock was not acquired despite completing retry loop", {
321+
name,
322+
resources: sortedResources,
323+
maxRetries,
324+
totalWaitTime: Math.round(totalWaitTime),
325+
lastError: lastError?.message,
326+
});
327+
throw new LockAcquisitionTimeoutError(
328+
sortedResources,
329+
Math.round(totalWaitTime),
330+
maxRetries + 1,
331+
`Lock acquisition on resources [${sortedResources.join(", ")}] failed unexpectedly`
332+
);
333+
}
334+
318335
// Create an AbortController for our signal
319336
const controller = new AbortController();
320337
const signal = controller.signal as redlock.RedlockAbortSignal;

0 commit comments

Comments
 (0)