node-tools: a stopping tool runner takes its subscriptions down, so callers meet no responders (issue 721)

The runner answered each call it did not take once its stop began with the typed fault
stopping (#90). Callers built before mesh-sdk read it as the callee's refusal and ended their
kept call, and no edge delivered the new answer after its readers. Now, once told to stop,
the runner first drains every subscription it answers calls on (a tool's, a seat verb's and
a seat proof's) and subscribes none again, then finishes the calls in flight within
drain-bound. A call made after the stop meets no responders at once, a transport fault every
caller of every mesh-sdk already waits out, until the new runner subscribes. A call that
still reached it is answered nothing, as H-A-369 has it. The typed answer goes whole: the
reply's error-kind, KindedError, ErrorKindStopping and the bundle's error data.

Tests: 721/AC4 in the bus (a call and a proof after the stop meet no responders within a
second, the call in flight is answered, a subject served after the stop is refused) and in
launch (a call that still reaches the runner gets no answer and no typed fault); the whole
test meets no responders while a call is still in flight, before the drain bound.

Builds: design 47 H2 H-A-570 (1), (3) (mesh-tools' part), amending §813 (12) as H-A-369 has it
This commit is contained in:
2026-11-23 16:35:15 +01:00
parent e8f58540ee
commit 662b05ca5a
9 changed files with 162 additions and 123 deletions
+23 -11
View File
@@ -195,8 +195,8 @@ func (c *Conn) SeatProve(module, subject string, body json.RawMessage) (json.Raw
}
// SeatAnswer answers every proof on a subject the module's seat traffic lists among its answers, with what
// answer returns. A returned error is answered as `{"error": "<words>"}`, with its `error-kind` when it names one (a proof
// after the stop: stopping, design 47 H2 H-A-542), never as silence, but for one that says it is unanswered (cut at the bound).
// answer returns. A returned error is answered as `{"error": "<words>"}`, never as silence, but for one that says it is
// unanswered (a proof after the stop or cut at the bound). The runner's stop takes the subscription down (StopAnswering).
func (c *Conn) SeatAnswer(module, subject string, answer func(subject string, body json.RawMessage) (json.RawMessage, error)) (func(), error) {
t, err := c.trafficOf(module)
if err != nil {
@@ -210,6 +210,9 @@ func (c *Conn) SeatAnswer(module, subject string, answer func(subject string, bo
return nil, fmt.Errorf("%s does not answer %s: its membership lists %s (novox/hq ADR 0259)", module,
subject, strings.Join(t.Answers, ", "))
}
if err := c.answersAreDown(subject); err != nil {
return nil, err
}
sub, err := c.nc.Subscribe(subject, func(msg *nats.Msg) {
if msg.Reply == "" {
return
@@ -220,19 +223,14 @@ func (c *Conn) SeatAnswer(module, subject string, answer func(subject string, bo
return
}
out, err := answer(msg.Subject, body)
// A proof cut at the runner's drain bound is answered nothing, as answerCalledOn does (design 47 H2 §813 (12),
// H-A-369); one after the stop is answered stopping below (H-A-542).
// A proof arriving after the runner's stop, or cut at its bound, is answered nothing, as answerCalledOn does
// (design 47 H2 §813 (12), H-A-369).
var unanswered interface{ Unanswered() bool }
if errors.As(err, &unanswered) && unanswered.Unanswered() {
return
}
if err != nil {
said := map[string]string{"error": err.Error()}
// A typed fault beside the words: a stopping tool runner's stopping (design 47 H2 H-A-542).
if kind := errorKindOf(err); kind != "" {
said["error-kind"] = kind
}
b, _ := json.Marshal(said)
b, _ := json.Marshal(map[string]string{"error": err.Error()})
_ = msg.Respond(b)
return
}
@@ -247,8 +245,22 @@ func (c *Conn) SeatAnswer(module, subject string, answer func(subject string, bo
return nil, err
}
c.track(sub)
// Kept among the proofs the stop takes down (design 47 H2 H-A-570 (1)).
c.mu.Lock()
if c.proofs == nil {
c.proofs = map[*nats.Subscription]bool{}
}
c.proofs[sub] = true
c.mu.Unlock()
var once sync.Once
return func() { once.Do(func() { _ = sub.Unsubscribe() }) }, nil
return func() {
once.Do(func() {
c.mu.Lock()
delete(c.proofs, sub)
c.mu.Unlock()
_ = sub.Unsubscribe()
})
}, nil
}
// Work is one message a holder took from a seat's work queue.