Design 47 G start: SDK fixes placed by hand #196

Merged
mesh-tools merged 13 commits from fix/47-G-start-3 into main 2026-11-16 14:15:09 +00:00
Showing only changes of commit 9ec8a88cb0 - Show all commits
+24 -2
View File
@@ -108,14 +108,36 @@ func callKeptWith(request func(string, []byte) (json.RawMessage, error), called,
func askBoth(request func(string, []byte) (json.RawMessage, error), called, fallback string,
data []byte) func() (json.RawMessage, error) {
return func() (json.RawMessage, error) {
start := time.Now()
result, err := request(called, data)
if errors.Is(err, nats.ErrNoResponders) {
result, err = request(fallback, data)
if !errors.Is(err, nats.ErrNoResponders) {
return result, unansweredOn(err, start, called)
}
first := err
start2 := time.Now()
result, err = request(fallback, data)
if err != nil && !isAnswered(err) {
return result, fmt.Errorf("asked on %s (%v), then on %s, unanswered after %s: %w", called, first, fallback,
time.Since(start2).Round(time.Millisecond), err)
}
return result, err
}
}
// unansweredOn names the subject a transport fault was met on and how long it waited, so a log of a call nobody
// answered says where it was asked; a callee's answer keeps its own words.
func unansweredOn(err error, start time.Time, subject string) error {
if err == nil || isAnswered(err) {
return err
}
return fmt.Errorf("asked on %s, unanswered after %s: %w", subject, time.Since(start).Round(time.Millisecond), err)
}
func isAnswered(err error) bool {
var a *busretry.Answered
return errors.As(err, &a)
}
// callOn asks called, then fallback when nothing answers it; while the bus itself answers nothing (a user-list reload
// drops the account's imports for a few seconds, busretry) both are asked again, within busretry.Bound. A call nobody
// answers on a bus that answers is not asked again: its callee is not running. A call that may have been delivered (a