node-tools: a serve racing the runner's stop is taken down too (issue 721, review round 1)

A tool's or a proof's subscription made while the stop took its snapshot was registered
after it, so it stayed subscribed until the close and its callers waited out their bound
instead of meeting no responders (the review's probe: 4 of 2000 rounds). Now a new
answering subscription is kept, and the stop checked again, in one section under the lock
the stop takes its subscriptions down under; when the stop began meanwhile, it is drained
and the serve refused.

Tests: 721/AC4 rows in the bus (a tool's serve and a proof answerer each run the stop
between their subscription and its keeping, through a test hook, and are refused; their
callers meet no responders), failing without the locked check.

Builds: design 47 H2 H-A-570 (1)
This commit is contained in:
2026-11-23 16:51:00 +01:00
parent 662b05ca5a
commit 5d87f7d375
5 changed files with 82 additions and 14 deletions
@@ -290,4 +290,17 @@ func TestARunnerAtItsStopAnswersNoCallAndItsCallersMeetNoResponders(t *testing.T
if err := <-held; err != nil {
t.Errorf("the call in flight at the stop ended %v, want it answered", err)
}
// A serve racing the stop (a membership change, a bundle's new tool): the stop begins between its subscription and its
// keeping, and still the subject is not left answered, its subscription taken down and the serve refused.
raced := dial(t, url, "ledger", "anchor", "")
var once sync.Once
bus.SetSubscribedHook(raced, func(string) { once.Do(raced.StopAnswering) })
if _, err := raced.HandleSubjectCalled("mesh.mod.ledger.tool.raced", func(string, string, json.RawMessage) (any, error) {
return map[string]any{"raced": true}, nil
}); err == nil {
t.Error("a serve that raced the stop was kept, want it refused")
}
if answered, err := asker.AskWithin("ledger.raced", map[string]any{}, "", 5*time.Second); !errors.Is(err, bus.ErrNoResponders) {
t.Errorf("a call of a tool whose serve raced the stop was answered %s, %v; want no responders", answered.Result, err)
}
}