Skip to content

Commit f498c37

Browse files
committed
fix(cleanup): recheck orphan condition in delete to close TOCTOU gap
1 parent d2187a4 commit f498c37

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

apps/sim/lib/logs/execution/snapshot/service.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,17 @@ export class SnapshotService implements ISnapshotService {
120120
const ids = candidates.map((c) => c.id)
121121
const deleted = await db
122122
.delete(workflowExecutionSnapshots)
123-
.where(inArray(workflowExecutionSnapshots.id, ids))
123+
.where(
124+
and(
125+
inArray(workflowExecutionSnapshots.id, ids),
126+
notExists(
127+
db
128+
.select({ one: sql`1` })
129+
.from(workflowExecutionLogs)
130+
.where(eq(workflowExecutionLogs.stateSnapshotId, workflowExecutionSnapshots.id))
131+
)
132+
)
133+
)
124134
.returning({ id: workflowExecutionSnapshots.id })
125135

126136
totalDeleted += deleted.length

0 commit comments

Comments
 (0)