Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions internal-packages/run-engine/src/run-queue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,9 @@ export class RunQueue {
onError?: (error: Error) => void
): { stream: Readable; redis: Redis } {
const pattern = this.keys.currentConcurrencySetKeyScanPattern();
const stream = this.redis.scanStream({
const redis = this.redis.duplicate();

const stream = redis.scanStream({
match: pattern,
count,
type: "set",
Expand All @@ -925,7 +927,7 @@ export class RunQueue {

return {
stream,
redis: this.redis,
redis,
};
}

Expand Down Expand Up @@ -1938,11 +1940,23 @@ export class RunQueue {
);
});

const [scanError] = await tryCatch(promise);

if (scanError) {
this.logger.error("Error scanning concurrency sets", {
error: scanError,
});
}

await redis.quit();

return promise;
}
Comment on lines +1943 to 1954
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure scan always completes on abort and return concrete stats; close client in finally.

If the AbortSignal fires before any data/end/error, the promise can hang. Also, returning the already-settled promise is awkward and drops stats.

Apply this diff:

-    const [scanError] = await tryCatch(promise);
-
-    if (scanError) {
-      this.logger.error("Error scanning concurrency sets", {
-        error: scanError,
-      });
-    }
-
-    await redis.quit();
-
-    return promise;
+    const onAbort = () => {
+      stream.destroy();
+      resolve(stats);
+    };
+    this.abortController.signal.addEventListener("abort", onAbort, { once: true });
+
+    try {
+      const result = await promise;
+      return result;
+    } catch (scanError) {
+      this.logger.error("Error scanning concurrency sets", { error: scanError });
+      throw scanError;
+    } finally {
+      this.abortController.signal.removeEventListener("abort", onAbort);
+      await redis.quit();
+    }

Committable suggestion skipped: line range outside the PR's diff.


private async processConcurrencySet(concurrencyKey: string) {
const stream = this.redis.sscanStream(concurrencyKey, {
const redis = this.redis.duplicate();

const stream = redis.sscanStream(concurrencyKey, {
count: 100,
});

Expand Down Expand Up @@ -1991,6 +2005,16 @@ export class RunQueue {
stream.resume();
});

const [scanError] = await tryCatch(promise);

if (scanError) {
this.logger.error("Error scanning concurrency sets", {
error: scanError,
});
}

await redis.quit();

return promise;
}

Expand Down
Loading