Skip to content

Commit 244d42e

Browse files
committed
fix(workflow): close stale reaper races
1 parent e0b078a commit 244d42e

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

src/workflow-lifecycle.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,14 @@ export function startWorkflowReaper(
115115
const staleAfterMs = Math.max(1, options.staleAfterMs ?? DEFAULT_STALE_AFTER_MS);
116116

117117
const tick = (): void => {
118-
const store = createWorkflowStore(config);
118+
let store: WorkflowStore | undefined;
119119
try {
120+
store = createWorkflowStore(config);
120121
reapStaleWorkflows(store, staleAfterMs);
121122
} catch (error) {
122123
options.onError?.(error);
123124
} finally {
124-
store.close();
125+
store?.close();
125126
}
126127
};
127128

src/workflow-store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,9 +764,9 @@ export class WorkflowStore {
764764

765765
const reaped: WorkflowRunRecord[] = [];
766766
for (const row of candidates) {
767-
if (row.pid !== null && isPidAlive(row.pid)) continue;
768767
const latest = this.getRun(row.id);
769768
if (!latest || (latest.status !== "running" && latest.status !== "starting")) continue;
769+
if (latest.pid !== undefined && isPidAlive(latest.pid)) continue;
770770
const failed = this.failRun(row.id, {
771771
error: latest.status === "starting" ? "workflow worker failed to start" : "worker heartbeat lost",
772772
errorKind: "heartbeat",

0 commit comments

Comments
 (0)