Tool runner: a bundle's over-long line ends the bundle and is said; an unanswered call and a refused answer are logged (issue 1966)
The reader of a bundle's stdout stopped at a line over 16 MiB without a word and the bundle's next write blocked for good: every call of the module then timed out, unheard of. Now the line is said, the bundle ended and started again by the exit path. A call the bundle does not answer in time is logged with tool and caller, and a refused publish of an answer (to a caller's inbox) is said once per subject per minute. Quick fix: only the bundle that met it (mesh-hand-acts' answer is cut by its own module). Thorough fix, chosen: the runner guards every bundle, so the kind (a silent freeze of a module runtime) cannot recur for any module. Claude-Session: https://claude.ai/code/session_01NcbgfFfQ4Z9UE5jK32PmE5
This commit is contained in:
@@ -195,6 +195,8 @@ type Conn struct {
|
||||
calls callers
|
||||
// waits are the waits in flight by subject, each told when the bus refuses its subscription (wait.go).
|
||||
waits map[string]map[chan string]bool
|
||||
// inboxSaid is when a refused answer publish was last said, by subject (answerRefused).
|
||||
inboxSaid map[string]time.Time
|
||||
}
|
||||
|
||||
// answered is one subject the runtime answers on: what to subscribe again with, and how often it was
|
||||
@@ -232,6 +234,9 @@ func (c *Conn) refused(err error) {
|
||||
if c.publishRefused(err) {
|
||||
return
|
||||
}
|
||||
if c.answerRefused(err) {
|
||||
return
|
||||
}
|
||||
if subject := subjectRefused(err); subject != "" && c.waitRefused(subject) {
|
||||
return
|
||||
}
|
||||
@@ -1215,3 +1220,28 @@ func keyOf(subject string) string {
|
||||
}
|
||||
return event
|
||||
}
|
||||
|
||||
// answerRefused says a refused publish of an answer (to a caller's inbox: a permission, or the single-use
|
||||
// allowance of a reply expired) once per subject per minute, never silently (issue 1966: a caller waited out its
|
||||
// time for an answer the bus had refused). It reports whether the refusal was one.
|
||||
func (c *Conn) answerRefused(err error) bool {
|
||||
m := refusedPublish.FindStringSubmatch(err.Error())
|
||||
if len(m) < 2 || !strings.HasPrefix(strings.Trim(m[1], `"`), "_INBOX.") {
|
||||
return false
|
||||
}
|
||||
subject := strings.Trim(m[1], `"`)
|
||||
c.mu.Lock()
|
||||
if c.inboxSaid == nil {
|
||||
c.inboxSaid = map[string]time.Time{}
|
||||
}
|
||||
last, seen := c.inboxSaid[subject]
|
||||
say := !seen || time.Since(last) >= time.Minute
|
||||
if say {
|
||||
c.inboxSaid[subject] = time.Now()
|
||||
}
|
||||
c.mu.Unlock()
|
||||
if say && c.Logf != nil {
|
||||
c.Logf("[mesh-tools] the bus refused this account an answer to %s (%v); the caller gets none", subject, err)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -84,3 +84,28 @@ func TestARefusedSubscriptionIsAskedForAgain(t *testing.T) {
|
||||
t.Error("a stopped subject is still tracked")
|
||||
}
|
||||
}
|
||||
|
||||
// Issue 1966: a refused publish of an answer (to a caller's inbox) is said, once per subject per minute, never dropped
|
||||
// in silence while the caller waits out its time.
|
||||
func TestARefusedAnswerIsSaidOncePerMinute(t *testing.T) {
|
||||
c := &Conn{}
|
||||
var said []string
|
||||
c.Logf = func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) }
|
||||
refuse := func(subject string) bool {
|
||||
return c.answerRefused(fmt.Errorf("%w: Permissions Violation for Publish to %q", nats.ErrPermissionViolation, subject))
|
||||
}
|
||||
if !refuse("_INBOX.user.abc") || !refuse("_INBOX.user.abc") || !refuse("_INBOX.user.def") {
|
||||
t.Fatal("a refused answer was not taken for one")
|
||||
}
|
||||
if len(said) != 2 {
|
||||
t.Fatalf("want one line per subject, got %v", said)
|
||||
}
|
||||
c.inboxSaid["_INBOX.user.abc"] = time.Now().Add(-2 * time.Minute)
|
||||
refuse("_INBOX.user.abc")
|
||||
if len(said) != 3 || !strings.Contains(said[2], "_INBOX.user.abc") {
|
||||
t.Fatalf("a minute later it is said again, got %v", said)
|
||||
}
|
||||
if refuse("mesh.mod.x.tool.y") {
|
||||
t.Fatal("a refused publish that is no answer was taken for one")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user