Skip to content

fix: report a concurrent duplicate subscription as already subscribed - #61

Merged
flthibaud merged 1 commit into
developfrom
fix/subscribe-double-submit
Nov 11, 2026
Merged

flthibaud merged 1 commit into
developfrom
fix/subscribe-double-submit

Conversation

@flthibaud

Copy link
Copy Markdown
Owner

Subscribe checked Exists and then inserted. Two concurrent requests both passed the check and the second hit UNIQUE(user_id, feed_id), which came back as a 500.

  • SubscriptionModel.Insert maps that unique violation to data.ErrDuplicateSubscription; Subscribe translates it to ErrAlreadySubscribed (422).
  • SubscriptionModel.Exists and its call are removed, and the subscriptionStore interface shrinks.
  • New DB test TestSubscriptionInsertDuplicate; the service test now drives the duplicate through Insert.

Tested with gofmt, go vet ./... and go test -race ./... against a migrated postgres:16 (no test skipped).

Closes #23

@flthibaud

Copy link
Copy Markdown
Owner Author

Review: OK to merge.

  • Code and tests by Mistral, unchanged.
  • The constraint name subscriptions_user_id_feed_id_key is confirmed by the DB test passing on a real schema.
  • The orphan-feed cleanup still runs on a failed insert: the deferred DeleteIfOrphan is untouched and keeps its NOT EXISTS guard.
  • Not tested: two truly concurrent HTTP requests. The test inserts the duplicate sequentially, which exercises the same constraint.

@flthibaud
flthibaud merged commit ef633c3 into develop Nov 11, 2026
5 checks passed
@flthibaud
flthibaud deleted the fix/subscribe-double-submit branch November 11, 2026 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Double-submitting a subscription returns 500 instead of "already subscribed"

1 participant