From e43a17a8db81a1cbadc54ea8188efbedad26ed66 Mon Sep 17 00:00:00 2001 From: Dexter Date: Thu, 15 Oct 2026 15:00:29 +0800 Subject: [PATCH 1/2] di.torq.proc.gateway: register backends that connect after startup registerbackends ran only at init and at EOD reloadend, so a backend that was down when the gateway started was never copied into di.serverselect - the registry di.asyncdispatch routes on. di.torq.servers' retry does reconnect it, leaving the gateway holding a live handle it could not route to until a restart or the next EOD. Hook registerbackends onto .servers.connectcustom, which retryrows fires on every successful new connection. registerbackends is already idempotent and re-reads the whole registry, so it ignores the rows it is handed. The .z.pc side already deactivated a backend on disconnect - this completes the pair. Verified against the TorqX-POC stack: starting gateway1 with rdb1 down and then starting rdb1 leaves the rdb connected-but-unroutable on main, and routable here within one retry interval, with no gateway restart. Co-Authored-By: Claude Opus 5 --- di/torq/proc/gateway/gateway.q | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/di/torq/proc/gateway/gateway.q b/di/torq/proc/gateway/gateway.q index 2dcdb82b..eeffc5ee 100644 --- a/di/torq/proc/gateway/gateway.q +++ b/di/torq/proc/gateway/gateway.q @@ -108,6 +108,10 @@ init:{[config;deps] sconfig:config,(enlist`connections)!enlist .z.m.backendtypes; (.z.m.svc`startup)[sconfig]; registerbackends[]; + / a backend that was down at startup connects later through di.torq.servers' retry/discovery, + / which fires .servers.connectcustom - hook it so serverselect learns about the late arrival. + / Without this the gateway holds a live handle it can never route to until a restart or EOD. + set[`.servers.connectcustom;{[rows] registerbackends[]}]; / di.dataaccess - the getdata query-normalisation layer, on top of the SAME asyncdispatch / instance (idempotent use) so it dispatches via the callbacks/registry set up above. Partition From e42329279a829a34bd191aea152343a81879864c Mon Sep 17 00:00:00 2001 From: Dexter Date: Fri, 16 Oct 2026 16:28:58 +0800 Subject: [PATCH 2/2] di.torq.proc.gateway: test that a late backend becomes routable The suite could not reach init before - it only checked the export shape and that init rejects missing deps - so nothing covered the registry the gateway actually routes on. Mock the four injected deps (log, timer, handlers, servers) and let di.serverselect, di.asyncdispatch and di.dataaccess be the real modules, so init completes and the tests can assert against di.serverselect's table. The servers mock reports connections from a BACKENDS table a test can edit, which is what makes the late-connect case expressible at all. Covers: the hdb registers at init, an rdb that was down does not, init installs the .servers.connectcustom hook, and firing that hook the way retryrows does makes the late rdb routable without a restart. Removing the hook from gateway.q fails exactly these three and leaves the other nine passing. Co-Authored-By: Claude Opus 5 --- di/torq/proc/gateway/test.csv | 13 ++++++++++ di/torq/proc/gateway/test.q | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 di/torq/proc/gateway/test.q diff --git a/di/torq/proc/gateway/test.csv b/di/torq/proc/gateway/test.csv index a90cf563..52c25ca4 100644 --- a/di/torq/proc/gateway/test.csv +++ b/di/torq/proc/gateway/test.csv @@ -7,3 +7,16 @@ fail,0,0,q,gw.init[()!();(enlist`log)!enlist mlog],1,,init with log but no timer true,0,0,q,`init`asyncexec`asyncexecjpt`reload`version~key gw,1,,module exports init/asyncexec/asyncexecjpt/reload/version true,0,0,q,0