vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Stop a superseded build instead of leaving it to finish
3031e35772b7d5498c3cb1427424169889632ab5 · Keenan Nemetz · 11d ago · parent 3ae0f579
Stop a superseded build instead of leaving it to finish A push that replaced a branch tip canceled the older commit's queued runs but left a running one alone. With long jobs and a single-slot runner, the runner kept building a commit that was no longer on the branch while the new tip's jobs waited. A rewrite can leave that commit unreachable entirely: on rack's seam-joint branch the old tip ran for 27m38s after the branch had moved, with 12 jobs queued behind it. CancelSuperseded now asks a running run for the replaced commit to stop too: it sets cancel_requested and leaves the lease, which is the path a manual cancel already uses. The runner stops at its next heartbeat, RecordAttempt keeps the result canceled rather than failed, and RequeueExpired already cancels a requested stop whose runner vanished instead of making it leasable again. The stale-deploy test moves its second commit with a fetch instead of a push: a push now stops the running build, and the deploy guard is what covers the window before the runner sees the request. It then pushes a third commit so the fresh-build half of the test still runs. Verified with go test ./server/ and vole workflow run verify.
server/ci_pages_test.go +30−11
| @@ -105,9 +105,9 @@ func TestWorkflowDeploysTheSite(t *testing.T) { | |||
| 105 | 105 | ||
| 106 | 106 | // TestWorkflowRefusesAStaleSiteDeploy is the guard: a build that is already running | |
| 107 | 107 | // when the branch moves must not publish, or the site would go backwards. The build is | |
| 108 | // held on a sentinel so the second commit lands while it is running — a run that is | ||
| 109 | // still queued at that moment is canceled instead of started, which is a different | ||
| 110 | // (and cheaper) answer. | ||
| 108 | // held on a sentinel so the tip moves while it is running. The move bypasses the push | ||
| 109 | // path on purpose: a push also asks a superseded running build to stop, and the guard | ||
| 110 | // is what covers the window before the runner sees that request. | ||
| 111 | 111 | func TestWorkflowRefusesAStaleSiteDeploy(t *testing.T) { | |
| 112 | 112 | t.Parallel() | |
| 113 | 113 | f := pagesCIFixture(t) | |
| @@ -133,7 +133,9 @@ func TestWorkflowRefusesAStaleSiteDeploy(t *testing.T) { | |||
| 133 | 133 | return r.ID == first.ID && r.Status == runs.StatusRunning | |
| 134 | 134 | }) | |
| 135 | 135 | ||
| 136 | // A second commit lands while the first build is still running. | ||
| 136 | // A second commit lands while the first build is still running, but it is not | ||
| 137 | // pushed: the fetch moves the branch without going through the queue, so the | ||
| 138 | // running build is not asked to stop and the deploy guard is what refuses it. | ||
| 137 | 139 | if err := os.WriteFile(filepath.Join(work, "site-note.txt"), []byte("second\n"), 0o644); err != nil { | |
| 138 | 140 | t.Fatal(err) | |
| 139 | 141 | } | |
| @@ -143,12 +145,10 @@ func TestWorkflowRefusesAStaleSiteDeploy(t *testing.T) { | |||
| 143 | 145 | if _, errs, err := runGit(t, work, "commit", "-qm", "second commit"); err != nil { | |
| 144 | 146 | t.Fatal(errs) | |
| 145 | 147 | } | |
| 146 | if _, errs, err := f.git(work, "push", f.sshURL(f.repo), "main:refs/heads/main"); err != nil { | ||
| 147 | t.Fatalf("second push: %s", errs) | ||
| 148 | bare := filepath.Join(f.cfg.ReposDir(), f.repo+".git") | ||
| 149 | if _, errs, err := runGit(t, bare, "fetch", "-q", work, "refs/heads/main:refs/heads/main"); err != nil { | ||
| 150 | t.Fatalf("move the tip: %s", errs) | ||
| 148 | 151 | } | |
| 149 | f.waitForRun(t, 5*time.Second, func(r *runs.Run) bool { | ||
| 150 | return r.Status == runs.StatusQueued && r.SHA != first.SHA | ||
| 151 | }) | ||
| 152 | 152 | ||
| 153 | 153 | // Let the held build finish; it is now building a commit that is no longer the tip. | |
| 154 | 154 | if err := os.WriteFile(sentinel, []byte("go\n"), 0o644); err != nil { | |
| @@ -164,16 +164,35 @@ func TestWorkflowRefusesAStaleSiteDeploy(t *testing.T) { | |||
| 164 | 164 | if !strings.Contains(log, "the site was not deployed") { | |
| 165 | 165 | t.Fatalf("stale run did not explain itself:\n%s", log) | |
| 166 | 166 | } | |
| 167 | if refs, _, _ := runGit(t, filepath.Join(f.cfg.ReposDir(), f.repo+".git"), | ||
| 167 | if refs, _, _ := runGit(t, bare, | ||
| 168 | 168 | "for-each-ref", "--format=%(refname)", "refs/heads/pages"); refs != "" { | |
| 169 | 169 | t.Fatalf("a stale build published a site: %q", refs) | |
| 170 | 170 | } | |
| 171 | 171 | ||
| 172 | 172 | // The newer run deploys normally, so the refusal is about staleness, not about CI | |
| 173 | 173 | // deploys being broken. | |
| 174 | if err := os.WriteFile(filepath.Join(work, "site-note-2.txt"), []byte("third\n"), 0o644); err != nil { | ||
| 175 | t.Fatal(err) | ||
| 176 | } | ||
| 177 | if _, errs, err := runGit(t, work, "add", "-A"); err != nil { | ||
| 178 | t.Fatal(errs) | ||
| 179 | } | ||
| 180 | if _, errs, err := runGit(t, work, "commit", "-qm", "third commit"); err != nil { | ||
| 181 | t.Fatal(errs) | ||
| 182 | } | ||
| 183 | third, _, err := runGit(t, work, "rev-parse", "HEAD") | ||
| 184 | if err != nil { | ||
| 185 | t.Fatal(err) | ||
| 186 | } | ||
| 187 | if _, errs, err := f.git(work, "push", f.sshURL(f.repo), "main:refs/heads/main"); err != nil { | ||
| 188 | t.Fatalf("third push: %s", errs) | ||
| 189 | } | ||
| 190 | f.waitForRun(t, 5*time.Second, func(r *runs.Run) bool { | ||
| 191 | return r.SHA == strings.TrimSpace(third) && r.Status == runs.StatusQueued | ||
| 192 | }) | ||
| 174 | 193 | f.runOnce(t) | |
| 175 | 194 | fresh := f.waitForRun(t, 10*time.Second, func(r *runs.Run) bool { | |
| 176 | return r.SHA != first.SHA && r.Status == runs.StatusSuccess | ||
| 195 | return r.SHA == strings.TrimSpace(third) && r.Status == runs.StatusSuccess | ||
| 177 | 196 | }) | |
| 178 | 197 | if fresh.ID == "" { | |
| 179 | 198 | t.Fatal("the newer run did not succeed") | |