Skip to content

Sub-account create race, Web Push drain on shutdown, gofmt - #75

Merged
markmnl merged 3 commits into
mainfrom
review-followups
Nov 26, 2026
Merged

markmnl merged 3 commits into
mainfrom
review-followups

Conversation

@markmnl

@markmnl markmnl commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Summary

Three follow-ups from the review of #71.

Sub-accounts: a failed create never disables an address that has a grant (fixes #72)

A create that registered or reinstated its address disables it again when no grant comes of it. It decided that from its own error and skipped the disable only on ErrAlreadyExists. The owner's limit is checked before the insert, so the loser of a race for the same address can be told the limit is reached instead, and it then disabled the address under the winner's live grant.

  • Before disabling, the store is asked whether the address has a grant, holding the lock that grant creation takes for the owner (Store.UnlessGranted). The error type only decides when the store can't be asked.
  • A create that found its address already registered confirms it accepts new messages once its own grant is stored, in case the create that registered it failed and undid the registration in between.
  • api-key create uses the same check, and opens the database before registering the address.

Web Push: send what is queued on shutdown instead of cancelling it (fixes #73)

Shutdown cancelled the push context before waiting, so pushes for messages committed just before or during the HTTP drain were dropped. Hub.DrainContext stops accepting jobs, lets the workers send what is queued and in flight, and cancels the remainder only when its 5 second deadline passes. The server-error exit path still cancels immediately.

gofmt on internal/handlers/transaction.go (one blank line).

Testing

  • New TestSubAccountCreateLoserLeavesWinnersAddress and TestSubAccountCreateConfirmsAddressItDidNotRegister interleave the two creates through a hook in the fake identity service. Both fail on main and pass here.
  • New TestHubDrainContext_SendsQueuedPushes and TestHubDrainContext_CancelsWhatIsLeftAtTheDeadline.
  • go vet ./... and go test -race ./... pass with the PostgreSQL-backed tests enabled (161 pass, none skipped).

🤖 Generated with Claude Code

markmnl and others added 3 commits November 26, 2026 10:08
A create that registered or reinstated its address disables it again when
no grant comes of it. It decided that from its own error, skipping the
disable only on ErrAlreadyExists. But the owner's limit is checked before
the insert, so the loser of a race for the same address can be told the
limit is reached instead, and it then disabled the address under the
winner's grant.

- Before disabling, ask the store whether the address has a grant, holding
  the lock grant creation takes for the owner (Store.UnlessGranted). The
  error only decides when the store can't be asked.
- A create that found its address already registered confirms it accepts
  once its own grant is stored, in case the create that registered it
  failed and undid the registration in between.
- api-key create (CLI) uses the same check, and opens the database before
  registering the address.

Fixes #72.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Shutdown cancelled the push context before waiting, so the 5 seconds it
allowed only bounded how long workers took to notice. Pushes for messages
committed just before or during the HTTP drain were dropped.

Hub.DrainContext stops accepting jobs, lets the workers send what is
queued and in flight, and cancels the remainder only when its deadline
passes. Graceful shutdown uses it; the server-error path still cancels.

Fixes #73.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@markmnl
markmnl merged commit 6e3102c into main Nov 26, 2026
1 check passed
@markmnl
markmnl deleted the review-followups branch November 26, 2026 02:41
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.

Drain queued Web Push jobs on shutdown instead of cancelling them Sub-account create can disable an address under a concurrent winner's grant

1 participant