From da7fbd20b80e9aec1141913e3e3d0e9f04f469fa Mon Sep 17 00:00:00 2001 From: atlas Date: Sun, 13 Sep 2026 11:51:18 +0200 Subject: [PATCH] swarm-queue-client: expose the announced payload limit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A publisher of variable-size rows has to size them against the server's limit before it publishes, because exceeding it is not a truncation: the server answers `Maximum Payload Violation` and closes the connection, so the row is lost and the client reconnects. The limit belongs to the queue's NixOS module, which is the only place that chooses it. Reading it off the connection rather than restating it as a constant keeps it spelled once — a client-side copy would be a second opinion about a number it does not own, and would go stale the day an operator raised the real one. No test: the value comes from the server's INFO line, so anything asserted about it without a running server would only be re-asserting async-nats's own pre-connect default. Refs #3805 --- swarm-queue-client/src/lib.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/swarm-queue-client/src/lib.rs b/swarm-queue-client/src/lib.rs index 809304ff..0d353be3 100644 --- a/swarm-queue-client/src/lib.rs +++ b/swarm-queue-client/src/lib.rs @@ -634,6 +634,26 @@ pub fn ensure_connected(client: &async_nats::Client) -> Result<(), Error> { Ok(()) } +/// The largest payload this connection's server will accept, as the server +/// itself announced it at CONNECT. +/// +/// Read it from here rather than from a constant: the limit is set in the +/// queue's own NixOS module, so a client that hardcoded it would be asserting +/// a number it does not own and would keep asserting it after the operator +/// raised it. A publisher that exceeds the limit does not get a shortened +/// message — the server answers `Maximum Payload Violation` and closes the +/// connection, costing the row and a reconnect — so a publisher of +/// variable-size rows must size them against this before handing them over. +/// +/// ⚠️ The value is per connection. Before the first successful CONNECT the +/// client reports the library's own default, which is smaller than any +/// deployment sets; call this after [`ensure_connected`], and the answer is +/// the one this server actually announced. +#[must_use] +pub fn max_payload(client: &async_nats::Client) -> usize { + client.server_info().max_payload +} + /// Connect to the swarm queue, presenting a token on each connection attempt /// and minting a fresh one only when the cached one is near expiry. ///