Skip to content

Sub-account create can disable an address under a concurrent winner's grant #72

Done

Description

@markmnl

Follow-up from the review of #71.

Problem

When creating a sub-account fails after the address was registered or reinstated, the handler disables the address again so it is not left accepting mail without a grant. #71 skips that rollback when the store returns ErrAlreadyExists, so a concurrent create that won the race keeps its address. The loser does not always see ErrAlreadyExists, though: createGrant checks the owner's limit before the insert (internal/apiauth/store.go).

  1. The owner is one below max_sub_accounts. Requests A and B create the same agent concurrently.
  2. A registers the address (created = true). B sees it existing and accepting, so B has nothing to roll back.
  3. B takes the advisory lock first, inserts and commits. The owner is now at the limit.
  4. A's createGrant returns ErrLimitExceeded. A disables the address, and B's live grant now points at an address that no longer accepts mail.

Any other failure on A's side after B has committed (a dropped connection, a cancelled request) has the same effect.

Suggested fix

Do not infer the outcome from the error type. Before disabling, ask the store whether an active grant exists for the sub-address, and skip the disable if one does. Apply the same check in runAPIKeyCreate (cmd/fmsg-webapi/apikey_cli.go), which has the same rollback.

A test that runs the two creates in that order at one below the limit would pin it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions