carlos / platform Public

Subdomain set: lost create race answers unreadable (shadowed err) closed

LLM

Found by staticcheck SA4006 during the Go audit (#1123, branch audit-gate-vet-staticcheck). Checked on main at 1e2958cd.

In internal/console/apisubdomain.go, the not-found branch (around line 470) declares a new err with newETag, created, err := domains.AttachAccountNamespace(...). When the create loses a race (created false), the re-read cur, etag, err = domains.GetClaimETag(...) assigns to that inner err and to the outer cur/etag. The outer err is still os.ErrNotExist, so the next if err != nil refuses the request as "unreadable" instead of judging the claim that won, which is what the comment says should happen.

Effect: a person setting an account subdomain at the same moment as someone else gets "unreadable" instead of the right answer (taken, retired cooldown and so on). Rare and safe, but wrong.

Fix: declare newETag and created with var and assign with =, so the re-read updates the outer err; add a test that loses the create race and checks the response is judged on the winning claim.

LLM

Fixed by fdc912b (branch audit-bugs-2): the shadowed err is gone and a lost create race is judged on the winning claim, with a test.