Title: flake: `TestAIGatewayKeysTableConstraints` (race on shared `err`) · Issue #25979 · coder/coder · GitHub
Open Graph Title: flake: `TestAIGatewayKeysTableConstraints` (race on shared `err`) · Issue #25979 · coder/coder
X Title: flake: `TestAIGatewayKeysTableConstraints` (race on shared `err`) · Issue #25979 · coder/coder
Description: Seen on PR #25928 in test-go-race-pg: https://github.com/coder/coder/actions/runs/26822469196/job/79080628504?pr=25928 Failing subtests: TestAIGatewayKeysTableConstraints/name_with_underscore TestAIGatewayKeysTableConstraints/name_longer...
Open Graph Description: Seen on PR #25928 in test-go-race-pg: https://github.com/coder/coder/actions/runs/26822469196/job/79080628504?pr=25928 Failing subtests: TestAIGatewayKeysTableConstraints/name_with_underscore TestA...
X Description: Seen on PR #25928 in test-go-race-pg: https://github.com/coder/coder/actions/runs/26822469196/job/79080628504?pr=25928 Failing subtests: TestAIGatewayKeysTableConstraints/name_with_underscore TestA...
Opengraph URL: https://github.com/coder/coder/issues/25979
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"flake: `TestAIGatewayKeysTableConstraints` (race on shared `err`)","articleBody":"Seen on PR #25928 in `test-go-race-pg`:\n\nhttps://github.com/coder/coder/actions/runs/26822469196/job/79080628504?pr=25928\n\nFailing subtests:\n\n- `TestAIGatewayKeysTableConstraints/name_with_underscore`\n- `TestAIGatewayKeysTableConstraints/name_longer_than_64_characters`\n- `TestAIGatewayKeysTableConstraints/duplicate_name`\n\n## Root cause\n\n`err` is declared once in the outer test function at `coderd/database/querier_test.go:14749` (`_, err := db.InsertAIGatewayKey(ctx, preExsiting)`) and then reassigned with `=` inside each parallel subtest at line 14831:\n\n```go\nfor _, tc := range tests {\n t.Run(tc.name, func(t *testing.T) {\n t.Parallel()\n\n ctx := testutil.Context(t, testutil.WaitShort)\n\n _, err = db.InsertAIGatewayKey(ctx, tc.params) // shared `err` from outer scope\n require.Error(t, err)\n requireAIGatewayKeysViolation(t, err, tc.expectUniqueErr, tc.expectCheckErr)\n })\n}\n```\n\nAll parallel subtests share the outer `err`. The race detector report points exactly at this:\n\n```\nWARNING: DATA RACE\nWrite at 0x00c000dc2ad0 by goroutine 855:\n ...TestAIGatewayKeysTableConstraints.func1()\n coderd/database/querier_test.go:14831 +0x144\n\nPrevious read at 0x00c000dc2ad0 by goroutine 846:\n ...TestAIGatewayKeysTableConstraints.func1()\n coderd/database/querier_test.go:14833 +0x1c7\n```\n\n## Fix\n\nChange `_, err = ...` to `_, err := ...` on line 14831 so each subtest gets its own `err`.\n\n## Provenance\n\nIntroduced by [32aee9ea4c feat: add DB queries for ai_gateway_coderd_keys (#25564)](https://github.com/coder/coder/commit/32aee9ea4c).\n\n---\n\n\u003csub>Filed by Coder Agents on behalf of @Emyrk.\u003c/sub>","author":{"url":"https://github.com/Emyrk","@type":"Person","name":"Emyrk"},"datePublished":"2026-06-02T13:42:18Z","url":"https://github.com/coder/coder/issues/25979"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fd2833f8-2577-4d0f-243a-dcd0f06c5281 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C9C4:13C1CF:1A40B7:22EE9D:6B016476 |
| html-safe-nonce | 687dd0ab8dc78aeba3dbdeb11958f8a1d779cfab858cc377f5101e5c3ee87c1c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOUM0OjEzQzFDRjoxQTQwQjc6MjJFRTlEOjZCMDE2NDc2IiwidmlzaXRvcl9pZCI6Ijc4MzUwNzAyODg4MTQ0OTg5MzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | bd14d130a2c876366542860aa951391606669d8020f47e6d47ba1c86abb631df |
| hovercard-subject-tag | issue:4571938210 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/coder/coder/25979/issue_layout |
| twitter:image | https://opengraph.githubassets.com/85a9775e1966e6f54cdad665ec793f15e0aec57d213c3e639a8736a2a031f793/coder/coder/issues/25979 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/85a9775e1966e6f54cdad665ec793f15e0aec57d213c3e639a8736a2a031f793/coder/coder/issues/25979 |
| og:image:alt | Seen on PR #25928 in test-go-race-pg: https://github.com/coder/coder/actions/runs/26822469196/job/79080628504?pr=25928 Failing subtests: TestAIGatewayKeysTableConstraints/name_with_underscore TestA... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Emyrk |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/coder/coder git https://github.com/coder/coder.git |
| octolytics-dimension-user_id | 95932066 |
| octolytics-dimension-user_login | coder |
| octolytics-dimension-repository_id | 440752086 |
| octolytics-dimension-repository_nwo | coder/coder |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 440752086 |
| octolytics-dimension-repository_network_root_nwo | coder/coder |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width