Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

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 · 10d 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.

ci/runs/runs.go +36−7

@@ -885,20 +885,49 @@ func (s *Store) Labels(id string) ([]string, error) {
885 885 return out, rows.Err()
886 886 }
887 887
888 // CancelSuperseded retires the queued runs of a ref that a newer tip replaced. Only
889 // waiting rows are touched: a job that is already running is not interrupted, because
890 // a canceled build is a different promise from a build nobody started. The caller
891 // decides when a push supersedes anything at all.
888 // CancelSuperseded retires the runs of a ref that a newer tip replaced. A queued run
889 // is canceled outright; a running one is asked to stop, because the commit it is
890 // building is no longer what the ref names, and its runner learns on the next
891 // heartbeat. Only push runs are touched: an event run is a new occurrence, not a
892 // replacement. The caller decides when a push supersedes anything at all.
892 893 func (s *Store) CancelSuperseded(repo, ref, keep string, now time.Time) (int, error) {
893 res, err := s.db.Exec(`UPDATE runs SET status = ?, finished = ?, lease_owner = '', lease_until = 0
894 tx, err := s.db.Begin()
895 if err != nil {
896 return 0, err
897 }
898 defer tx.Rollback()
899 queued, err := tx.Exec(`UPDATE runs SET status = ?, finished = ?, lease_owner = '', lease_until = 0
894 900 WHERE repo = ? AND ref = ? AND sha <> ? AND status = ?
895 901 AND trigger_kind IN ('', 'push')`,
896 902 StatusCanceled, now.Unix(), repo, ref, keep, StatusQueued)
897 903 if err != nil {
898 904 return 0, err
899 905 }
900 n, err := res.RowsAffected()
901 return int(n), err
906 q, err := queued.RowsAffected()
907 if err != nil {
908 return 0, err
909 }
910 // The lease stays with the runner, which still owns the process and will report
911 // the partial attempt. RecordAttempt keeps the result canceled rather than failed.
912 stopping, err := tx.Exec(`UPDATE runs SET cancel_requested = 1
913 WHERE repo = ? AND ref = ? AND sha <> ? AND status = ?
914 AND trigger_kind IN ('', 'push')`,
915 repo, ref, keep, StatusRunning)
916 if err != nil {
917 return 0, err
918 }
919 w, err := stopping.RowsAffected()
920 if err != nil {
921 return 0, err
922 }
923 if err := tx.Commit(); err != nil {
924 return 0, err
925 }
926 n := int(q + w)
927 if n > 0 {
928 s.notify()
929 }
930 return n, nil
902 931 }
903 932
904 933 // Session is one connected runner as the queue sees it: who it authenticated as,