mirror of
https://github.com/efiten/coredrive-rx.git
synced 2026-11-27 06:48:07 +00:00
A field log showed 59 records buffered and not one published, with ~18 "Keepalive timeout" errors against a single successful CONNACK. Probing the broker from a fixed line ruled out the obvious causes: publishes to /packets, /rf and /regions were all PUBACKed in ~85ms with returnCode=0 and no disconnect, and a deliberate same-clientId takeover makes the victim report a bare 'close', never a keepalive error. So neither the ACL nor session contention was involved. What was: two defects that together made a flaky mobile link unrecoverable and undiagnosable. 1. drain() discarded its own progress. It collected published ids and called queue.remove ONCE after the loop, so a single rejecting publish threw and every record the broker had already acknowledged stayed queued to be sent again. Publishes are sequential, so a 59-record backlog needs ~5s of continuous link at 86ms round-trip and ~18s at 300ms - on a link that stayed up about a second at a time, the design could never commit anything at all. The loop now lives in src/drain.js with two invariants under test: a record is removed if and only if the broker acked it, and one unpublishable record can never block the records behind it. A link drop is charged to the link, not to the record, so repeated drops cannot quarantine a good reception. 2. Every Publisher ever created reported into one module-level handler writing one global brokerState, so an orphaned client's endless 4s reconnect loop overwrote a healthy connection's state and filled the log with failures nothing could attribute. Each Publisher now carries an id; events from a retired one are named once and then ignored. startPublisher no longer ADOPTS a disconnected publisher (which made connectAll print "CoreScope connected" over a looping client) - it retires it, which also stops that loop. Also: keepalive is now set explicitly and quoted in the log next to the CONNACK return code. mqtt.js arms its keepalive manager only inside _onConnect and only if one does not already exist (client.js:1101), never re-arming an existing one, so a surviving manager can report a bogus timeout on a healthy link. That error is now evidence instead of a red herring. Tests: 234 pass (+14). SW cache v36 -> v37. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>