Serve the read verbs on the serving controller's own connection, and name every connection

Each verb ran as a process that dialled the bus, so hundreds of short
connections an hour, all named mesh-controller, hid any client reconnecting
in a loop (hq issue 327). D15 now says a user whose connections keep dropping.
This commit is contained in:
jochen
2026-10-08 21:08:34 +02:00
parent ca09a07fdf
commit 1e04670052
21 changed files with 744 additions and 80 deletions
+38
View File
@@ -0,0 +1,38 @@
package main
import (
"fmt"
"sync/atomic"
"github.com/novox/mesh-controller/internal/broker"
)
// The serving controller's own connection, lent to whatever it does for a moment (novox/hq issue 327).
//
// Every place that needed the bus for a moment dialled it: a verb's own process, and in the serving
// controller a watchdog tick reading whether the build seat paused, a walk's step reading readiness, a
// queue read. Each paid a connection, a TLS handshake and a login on the control node, and hundreds an
// hour hid in the server's connection total the one thing it would show: a client reconnecting in a loop.
// The serving controller is on the bus already; what it does is done on that connection.
// servingBus is the serving controller's connection, set when it starts serving; nil in every other
// process, which dials its own.
var servingBus atomic.Pointer[broker.JetStream]
// aBus is a connection for something done for a moment: the serving controller's own, lent — so its
// Close closes nothing — when this process is it, and otherwise one dialled for it, named for this
// process (broker.ConnectionName), which its Close closes.
func aBus() (*broker.JetStream, error) {
if serving := servingBus.Load(); serving != nil {
return broker.Borrow(serving), nil
}
address, err := broker.BusAddress()
if err != nil {
return nil, err
}
js, err := broker.Dial(address)
if err != nil {
return nil, fmt.Errorf("cannot reach the bus: %w", err)
}
return js, nil
}