Skip to content

Commit ece6094

Browse files
groupskyclaude
andcommitted
fix: review findings of /check
The path unit starts only on check/request; a run that waited for the lock and finds no request stops; install.sh names the check path unit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9095c14 commit ece6094

5 files changed

Lines changed: 15 additions & 6 deletions

File tree

‎DESIGN.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,10 @@ six bytes `check\n`. It holds nothing from the message: not the text, not
357357
a SHA, not a code. A check request can only start a normal run. It is not
358358
an approval, and `pullgate apply` never reads this directory.
359359

360-
`pullgate-check@NAME.path` watches the directory (`DirectoryNotEmpty=`) and
361-
starts `pullgate-run@NAME.service`, the unit of the timer. `pullgate run`,
362-
with the lock held:
360+
`pullgate-check@NAME.path` watches the file `check/request`
361+
(`PathExists=`; another file there starts nothing) and starts `pullgate-run@NAME.service`, the unit of the timer. `pullgate run`,
362+
with the lock held (a run that had to wait for the lock, and then finds
363+
no request, stops: the run before it took the request and replied):
363364

364365
1. Reads and removes every file in the directory, with the checks of an
365366
approval: through `os.OpenRoot` with `O_NOFOLLOW`, a regular file owned

‎contrib/systemd/pullgate-check@.path‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
Description=pullgate check requests for %i
77

88
[Path]
9-
DirectoryNotEmpty=/var/spool/pullgate/%i/check
9+
# Only the request file counts, so another file in the directory does not
10+
# start runs again and again.
11+
PathExists=/var/spool/pullgate/%i/check/request
1012
Unit=pullgate-run@%i.service
1113
# At most 10 starts a minute. This stops a loop when a run fails before it
1214
# removes the request. The listener writes at most one request per instance

‎install.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ print_restart() {
681681
fi
682682
say "This script restarts nothing. The listener still runs the old version. Restart it:"
683683
say " systemctl restart pullgate-listen.service"
684-
say "The timers (pullgate-run@NAME.timer) and the path units (pullgate-apply@NAME.path)"
684+
say "The timers (pullgate-run@NAME.timer) and the path units (pullgate-apply@NAME.path, pullgate-check@NAME.path)"
685685
say "start a new process each time, so they use the new file from their next start."
686686
say "A run or an apply that is running now ends with the old version. See them with:"
687687
say " systemctl list-timers 'pullgate-run@*'"

‎install_linux_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ func TestInstall(t *testing.T) {
539539
in.checkTmpGone()
540540
for _, s := range []string{"Installing pullgate 0.2.0 as " + in.bin + "/pullgate.", "version says: pullgate 0.2.0",
541541
"This script restarts nothing.", "systemctl restart pullgate-listen.service", "pullgate-run@NAME.timer",
542-
"pullgate-apply@NAME.path"} {
542+
"pullgate-apply@NAME.path", "pullgate-check@NAME.path"} {
543543
if !strings.Contains(r.stdout, s) {
544544
t.Errorf("stdout does not say %q:\n%s", s, r.stdout)
545545
}

‎internal/gate/run.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ func (e *Env) Run(ctx context.Context) (Result, error) {
125125
// the path unit does not start the run again and again.
126126
e.Log.Info("busy: a check request waits for the lock")
127127
lock, err = e.Dir.Lock(true)
128+
if err == nil && !e.Spool.HasCheck() {
129+
// The run that held the lock took the request and replied.
130+
_ = lock.Close()
131+
e.Log.Info("busy: the run before this one took the check request")
132+
return Busy, nil
133+
}
128134
}
129135
if err != nil {
130136
return "", err

0 commit comments

Comments
 (0)