Repository navigation
Description
Summary
The #7772 fix gives PostBatchHandler a capped CountingInputStream and a dedicated catch arm whose
whole point is that the refusal must not be mis-reported:
} catch (final RequestTooBigException e) {
// BEFORE the IOException arm below, which it extends. This is not a client that went away: it is this
// server declining to read past arcadedb.server.httpBodyContentMaxSize ...
// The arm below would report it as a truncated upload and point the operator at the streaming read
// timeout, which is the wrong knob and the wrong diagnosis.
...
throw e;That arm lives in streamRecords, which is the LEADER-side consumption of the body. On a follower,
execute returns into forwardBatchToLeader before streamRecords is ever reached, and the capped
stream is handed to the JDK HTTP client as the forwarded request's body publisher. When the cap trips
there, RequestTooBigException (an IOException) surfaces out of HttpClient.send and lands in that
method's final catch:
} catch (final Exception e) {
LogManager.instance().log(this, Level.WARNING, "Error forwarding /batch to leader at %s: %s", url, e.getMessage());
return new ExecutionResponse(503,
"{ \"error\" : \"Error forwarding batch to leader: " + e.getMessage().replace("\"", "'") + "\"}");
}It is RETURNED, not thrown, so AbstractServerHttpHandler.sendMappedErrorResponse's new 413 arm never
runs. The client gets a 503 - a status every retrying client treats as "the cluster is momentarily
unavailable, send it again" - for a request that can only ever be refused, and the follower's own log
blames the leader and the network for what is this node's configured body cap. This is the exact
mis-diagnosis the new catch arm was written to prevent, on the one path it was not added to.
Only reachable for a body with no declared length (chunked, or HTTP/2 with no content-length): a
declared oversize length is still refused by HttpServer.createBodySizeLimitHandler before routing, on
the follower as on the leader. That is the same population #7772 itself is about.
Where (HEAD 9a88be7)
server/src/main/java/com/arcadedb/server/http/handler/PostBatchHandler.java:353 builds the capped
stream; :367 returns into the forwarding path before streamRecords; :577 is the
RequestTooBigException arm that only the leader path reaches; :1946 (catch (final Exception e) in
forwardBatchToLeader) is where the refusal actually lands; :2013 shows the stream being wrapped as
HttpRequest.BodyPublishers.ofInputStream(oneShotBody).
Repro
Not reproduced - it needs a live two-node Raft cluster. By code read: POST /api/v1/batch/{db} to a
FOLLOWER with Transfer-Encoding: chunked and more than arcadedb.server.httpBodyContentMaxSize bytes
of NDJSON. The same request against the leader answers 413 {"error": {... "Request body too large (arcadedb.server.httpBodyContentMaxSize)" ...}} via sendMappedErrorResponse;
Issue7772ChunkedBodySizeLimitTest.chunkedBodyOverLimitIsRefusedOnTheStreamingBatchEndpoint pins that
single-node shape only.
Suggested fix
In forwardBatchToLeader, add a catch (final RequestTooBigException e) (or unwrap it from the
IOException the JDK client surfaces) ahead of the generic catch (Exception e), and rethrow it so the
same sendMappedErrorResponse arm builds the 413 it builds for every other route. The follower's log
line should name arcadedb.server.httpBodyContentMaxSize rather than the leader's URL.
Scope / confidence
Code read, high confidence on the control flow: the capped stream is the one handed to
buildForwardRequest, RequestTooBigException extends IOException, and forwardBatchToLeader's last
arm catches Exception and RETURNS a response rather than rethrowing. Tried to refute it three ways:
(a) that some other production call site builds the stream uncapped - there is exactly one production
construction (:353), the two-argument uncapped constructor has only test callers; (b) that the
streaming NDJSON path answers differently - streamRecordsAsNdJson delegates to streamRecords and
rethrows when nothing has been written, so the LEADER side is right there too, which only sharpens the
follower/leader disagreement; (c) that createBodySizeLimitHandler catches it first - it cannot, it
reads getRequestContentLength(), which is -1 for a chunked body.
Activity
ruispereira commentedon Sep 24, 2026
Still valid at HEAD
1865ae08fd, with one thing worth recording so nobody reads a neighbouring change as superseding it.PostBatchHandler.javaWAS edited in this window, by5b49aa6a95(#7396, "reports its real status in band"). That change extracted the error classification into one chain and hadPostBatchHandlerread it rather than copy it. It did not touch this: theRequestTooBigExceptionarm is still instreamRecordsonly, andforwardBatchToLeader's tail still returns a 503 rather than rethrowing, so a follower still answers 503 where the leader answers the documented JSON 413.Sharper than when filed, in fact:
forwardBatchToLeaderhas since grown four typed catch arms ahead of the generic one (Interrupted, ConnectTimeout, Connect, HttpTimeout), each with a comment explaining why the generic arm was wrong for it.RequestTooBigExceptionis now the single remaining case of that same argument with no arm of its own.ruispereira commentedon Sep 28, 2026
Re-checked at HEAD
92b58a206e. Still valid, and the tree now states the invariant the defect breaks.PostBatchHandler's local arm at:580carries a comment saying it rethrows deliberately, "so the 413 is built in the one place that builds it for every other route -sendMappedErrorResponse". That is the contract this issue says the follower path does not keep.Of the three leader forwarders, two now honour it:
LeaderCommandForwarder:740andRaftReplicatedDatabase:4058both throw.PostBatchHandler:2044is the only one that returns a hand-built 503, and so the only one that can never produce the documented 413.Line corrections:
:578is now:580, and:1947is now:2045.review(#8161): volatile body failure, IPv4 fake leader, assert the 41…
review(#8161): shorter comments, local refusal before the volatile wr…
review(#8161): check the cap in the read-timeout arm too, log the cap…
review(#8161): say why the read-timeout arm's cap check has no unit test
review(#8161): wait for the fake leader's accept instead of reading a…
review(#8161): log the follower's cap refusal at the leader's 413 lev…
fix(#8161): answer 413, not 503, when a follower's body cap cuts a fo…
ruispereira commentedon Sep 30, 2026
Verified fixed on main at `6a127cc7ce` by 6a127cc (#8675), and this can be closed.
`PostBatchHandler` now has the typed `catch (final RequestTooBigException e)` arm (`:584`), and it rethrows rather than answering in place, so the 413 is built in the one place that builds it for every other endpoint. That is exactly the asymmetry this issue was about, and the shape suggested here.
`Issue8161FollowerForwardBodyCapTest` pins it.
robfrank commentedon Sep 30, 2026
Fixed by #8675. A chunked
POST /api/v1/batchlarger thanarcadedb.server.httpBodyContentMaxSizesent to a follower used to come back as a 503 "Error forwarding batch to leader", because the size refusal surfaced wrapped inside the relay's I/O error. The follower now checks whether its own body cap cut the request and, if so, answers the same JSON 413 the leader does. Genuine forwarding failures on a request under the cap still answer 503.Still open:
/batchdoes not mean nothing was applied, since records loaded before the cut stay committed.❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.
fix(#8161): answer 413, not 503, when a follower's body cap cuts a fo…