Skip to content

lockPull: check isActive in the transaction and only by different nodes #2117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Changes from 2 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
7 changes: 2 additions & 5 deletions packages/api/src/controllers/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1103,16 +1103,13 @@ app.post("/:id/lockPull", authorizer({ anyAdmin: true }), async (req, res) => {
res.status(404);
return res.json({ errors: ["not found"] });
}
if (stream.isActive) {
return res.status(423).end();
}

const updateRes = await db.stream.update(
[
sql`id = ${stream.id}`,
sql`data->>'pullLockedBy' = ${host} OR COALESCE((data->>'pullLockedAt')::bigint,0) < ${
sql`data->>'pullLockedBy' = ${host} OR (COALESCE((data->>'pullLockedAt')::bigint,0) < ${
Date.now() - leaseTimeout
}`,
} AND COALESCE((data->>'isActive')::boolean,FALSE) = FALSE)`,
],
{ pullLockedAt: Date.now(), pullLockedBy: host },
{ throwIfEmpty: false }
Expand Down
Loading