fix(streaming): race condition on concurrent stream starts #28
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
startStream() uses a find-then-insert check for an existing active
stream, which isn't atomic — two concurrent start requests for the
same user can both pass the check before either commits, resulting
in two active stream rows.
Proposed fix: add a partial unique index (user_id WHERE end_time IS
NULL) so Postgres enforces "one active stream per user" at the DB
level. startStream() would then rely on the constraint instead of
the pre-check, translating a DataIntegrityViolationException into
the existing AlreadyStreaming exception.