Title: Duplicate name when creating a new workspace build (transition): `pq: duplicate key value violates unique constraint "workspace_builds_workspace_id_name_key"` · Issue #3038 · coder/coder · GitHub
Open Graph Title: Duplicate name when creating a new workspace build (transition): `pq: duplicate key value violates unique constraint "workspace_builds_workspace_id_name_key"` · Issue #3038 · coder/coder
X Title: Duplicate name when creating a new workspace build (transition): `pq: duplicate key value violates unique constraint "workspace_builds_workspace_id_name_key"` · Issue #3038 · coder/coder
Description: This is an issue we ran into CI, it's a rare occurrence but there's a non-zero chance it can happen to our users as well. Problem: When a new workspace build is created for an existing workspace (e.g. transition into deleted) a new (uniq...
Open Graph Description: This is an issue we ran into CI, it's a rare occurrence but there's a non-zero chance it can happen to our users as well. Problem: When a new workspace build is created for an existing workspace (e...
X Description: This is an issue we ran into CI, it's a rare occurrence but there's a non-zero chance it can happen to our users as well. Problem: When a new workspace build is created for an existing work...
Opengraph URL: https://github.com/coder/coder/issues/3038
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Duplicate name when creating a new workspace build (transition): `pq: duplicate key value violates unique constraint \"workspace_builds_workspace_id_name_key\"`","articleBody":"This is an issue we ran into CI, it's a rare occurrence but there's a non-zero chance it can happen to our users as well.\r\n\r\n**Problem:** When a new workspace build is created for an existing workspace (e.g. transition into deleted) a new (unique-ish) name is generated for that job via `namesgenerator.GetRandomName(1)`. Normally this should not be an issue, but we have a unique constraint on `(workspace_id, name)`:\r\n\r\n```sql\r\nALTER TABLE ONLY workspace_builds\r\n ADD CONSTRAINT workspace_builds_workspace_id_name_key UNIQUE (workspace_id, name);\r\n```\r\n\r\nThis results in a non-zero chance that both the create job and delete job receive the same `name`, resulting in the conflict. For very long lived workspaces, the chance of hitting this issue becomes greater. I did a local test that reproduced this after running workspace start/stop 200 times.\r\n\r\nThe CI run that hit this issue: https://github.com/coder/coder/runs/7399324482?check_suite_focus=true\r\n\r\n```\r\n2022-07-18T22:52:32.7769558Z workspaces_test.go:331: \r\n2022-07-18T22:52:32.7770135Z \tError Trace:\t/home/runner/work/coder/coder/coderd/workspaces_test.go:331\r\n2022-07-18T22:52:32.7770615Z \tError: \tReceived unexpected error:\r\n2022-07-18T22:52:32.7772201Z \t \tPOST http://127.0.0.1:42617/api/v2/workspaces/9a172a87-b686-4a93-a286-70d473562375/builds: unexpected status code 500: Internal error inserting workspace build.\r\n2022-07-18T22:52:32.7773646Z \t \t\tError: execute transaction: insert workspace build: pq: duplicate key value violates unique constraint \"workspace_builds_workspace_id_name_key\"\r\n2022-07-18T22:52:32.7774246Z \tTest: \tTestWorkspaceByOwnerAndName/Deleted\r\n2022-07-18T22:52:32.7774730Z \tMessages: \tdelete the workspace\r\n2022-07-18T22:52:32.7775638Z t.go:81: 2022-07-18 22:49:15.883 [DEBUG]\t(provisionerd)\t\u003cgithub.com/coder/coder/provisionerd/provisionerd.go:370>\t(*Server).closeWithError\tclosing server with error\t{\"error\": null}\r\n2022-07-18T22:52:32.7776288Z --- FAIL: TestWorkspaceByOwnerAndName/Deleted (6.92s)\r\n2022-07-18T22:52:32.7776505Z \r\n2022-07-18T22:52:32.7776777Z make: *** [Makefile:175: test-postgres] Error 1\r\n```\r\n\r\n**Questions**\r\n- Is there a good reason to keep unique names for all workspace builds (and all transitions)?\r\n- Should we try a new name on conflict?","author":{"url":"https://github.com/mafredri","@type":"Person","name":"mafredri"},"datePublished":"2022-07-19T11:41:09Z","url":"https://github.com/coder/coder/issues/3038"}
| 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:d84960c2-5ec2-f4e2-615d-93e9486caf76 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B0AE:3C21B:29D3595:356D4DA:6B0197B8 |
| html-safe-nonce | b70f8b3d30b903e853f5aa6f802ecccbd8d195f26f34bb5106e48a0064dbb403 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMEFFOjNDMjFCOjI5RDM1OTU6MzU2RDREQTo2QjAxOTdCOCIsInZpc2l0b3JfaWQiOiIxMjYwNTUzNTg4NzAzMzM2Mzc2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 41369d053a1032205cfd5ca8beacaef20a30398126c68c9a02068637cfb39cf0 |
| hovercard-subject-tag | issue:1309393098 |
| 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/3038/issue_layout |
| twitter:image | https://opengraph.githubassets.com/125c45e97b302cbf2bd8fac5498aded3530dc03dd8008b2c6e143c2783ad18c3/coder/coder/issues/3038 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/125c45e97b302cbf2bd8fac5498aded3530dc03dd8008b2c6e143c2783ad18c3/coder/coder/issues/3038 |
| og:image:alt | This is an issue we ran into CI, it's a rare occurrence but there's a non-zero chance it can happen to our users as well. Problem: When a new workspace build is created for an existing workspace (e... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mafredri |
| 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 | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width