Lock the workspace row when accepting an invitation

Open
#53 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
fastapi, postgresql, python

Research direction

Start with server/orcaster_server/workspaces/service.py and trace the invitation refusal hook through server/orcaster_server/auth/config.py and the join and register/complete routes in server/orcaster_server/auth/router.py. Check how those routes manage transactions and how existing invitation tests set up database sessions. Done means both acceptance routes hold a shared row lock through commit or rollback, the read-only invitation paths remain unlocked, and the requested concurrency and 410 cases pass.

Written by the indexing model from the issue text.

Description

bug P2 server

Problem

An invitation for a disabled workspace must never create a user, a session or a membership. The check and the commit are not atomic.

is_workspace_disabled runs a plain SELECT disabled_at with no row lock (server/orcaster_server/workspaces/service.py:147). It is reached through the is_invitation_refused hook (server/orcaster_server/auth/config.py:84) and _refused (server/orcaster_server/auth/router.py:114). The check runs at server/orcaster_server/auth/router.py:386 (register/complete) and server/orcaster_server/auth/router.py:284 (join), and the commit comes later (server/orcaster_server/auth/router.py:417 and :297). If the workspace is disabled after the check and before the commit, the acceptance still succeeds.

The window is small. It is wider if a slow step runs between check and commit.

Proposed change

Add a locking variant of the disabled check that uses SELECT disabled_at FROM workspaces WHERE id = ... FOR SHARE, and use it from the acceptance routes (register/complete and join). The lock is held until the route commits or rolls back. A concurrent update that sets disabled_at then waits for the acceptance to finish. Either the disable lands after the membership exists, or the acceptance sees disabled_at and answers 410. Both outcomes are consistent.

  • Keep the read-only invitation page free of the lock.
  • A workspace disabled after the acceptance keeps its new member. This is out of scope.

Acceptance criteria

  • register/complete reads the workspace row with FOR SHARE and keeps the lock until commit or rollback.
  • join does the same.
  • The read-only invitation page and describe_invitation take no row lock.
  • A test with two database sessions shows that setting workspaces.disabled_at blocks while an acceptance is in progress and lands after its commit. Same test for join.
  • A test shows that a disable committed before the check gives 410 and creates no user, session or membership.
  • Existing deployments keep working without configuration changes. The only visible effect is that an operator update of workspaces may wait for one acceptance transaction.
  • Existing invitation tests pass.
  • CHANGELOG entry under Unreleased.
Dominant language
Python
Stars
0
Forks
0
Avg merge
1d 1h
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AInvirion/orcaster

All issues in AInvirion/orcaster

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.