Repository navigation
Conversation
A positive divide rule requestMaxSize was only compared against the Content-Length header. Chunked or unknown-length requests report -1 for that header, so the comparison succeeded without examining a single body byte and oversized streaming bodies were forwarded. For unknown-length requests the limit is now enforced on the actual bytes: the request is decorated with a counting body that resets per subscription and aborts the stream with 413 (PAYLOAD_TOO_LARGE, which GlobalErrorHandler already honours) once the forwarded size exceeds the configured maximum. The known-length fast path is unchanged. Rebased onto current master, which moved the selection/forwarding into forwardSelected with canary routing and circuit-breaker candidates; the decorated exchange is threaded through the forwardSelected call. Regression test posts a 2-byte chunked body under a 1-byte limit and asserts a PAYLOAD_TOO_LARGE ResponseStatusException (red on the previous code, which forwarded it).
Aias00
left a comment
There was a problem hiding this comment.
The streaming guard is the right shape: it only engages when requestMaxSize > 0 and Content-Length is absent, so known-length bodies keep the existing fast path and there is no double accounting with the header check above it.
Two things to consider, neither blocking:
-
forwardedis a mutable field on the anonymous decorator, reset insideFlux.defer. That is correct for the sequential (and retry) case, because each subscription restarts the count. A concurrent second subscription ofgetBody()on the same exchange would race on it, though. If that can happen through the retry strategy, anAtomicLongremoves the doubt; otherwise a comment stating the single-subscription assumption is enough. -
The 413 is raised from inside the body
Flux, so it surfaces fromchain.execute(...)rather than from the plugin's return value. The test proves the error type reaches the subscriber, but please confirm it reaches the client as a 413 response body rather than a bare stream error — the header-based path above returns a normalWebFluxResultUtilsresult, so the two rejection paths would otherwise behave differently at the edge.
Approving; the above can be follow-ups.
|
/retest |
Sync to current master to resolve the stable shenyu-integrated-test-http CI failure (CachePluginTest.testMemoryModle/testRedisModle). Root cause: this branch predated #8079, whose pre-fix CachedResponse.capture() refused to store any response carrying a Vary header, so the cached endpoint was never reused and both requests hit the backend. #8079 keys Vary responses on the selecting request headers instead. Also pulls in the divide/loadbalancer work (#8076, #7172, #7986, #8005, #7821, #8033, #8090). #7172 removeStaleUpstreams reconciles via removeFromMap/triggerRemoveOne, which republish the immutable healthy snapshot under the same lock, so the read-only snapshot model stays correct with no stale retained instances.
Fixes #7816. Supersedes #7820 (approved, but it conflicted with master after #7857 moved the selection/forwarding into
forwardSelectedwith canary routing — this is the same fix rebased onto that structure, as requested in the review follow-up).Modifications
A positive divide rule
requestMaxSizewas only compared against theContent-Lengthheader. Chunked or unknown-length requests report-1, so the comparison succeeded without examining a single body byte — oversized streaming bodies were forwarded.For unknown-length requests the limit is enforced on the actual bytes: the request is decorated with a counting body that resets per subscription (
Flux.defer) and aborts the stream withResponseStatusException(PAYLOAD_TOO_LARGE)(whichGlobalErrorHandleralready honours) once the forwarded size exceeds the maximum. The known-length fast path is unchanged; the decorated exchange is threaded through theforwardSelectedcall so canary selection, attributes and circuit-breaker recording all operate on it.Verifying this change
doExecuteRejectsChunkedBodyExceedingRequestMaxSize— 2-byte chunked body under a 1-byte limit; the downstream drains the body and the stream must abort withResponseStatusExceptioncarryingPAYLOAD_TOO_LARGE. Red on the un-fixed code (verified by temporarily bypassing the decorator), green after../mvnw -pl shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide -am test -B— full module 103/103 green (all canary/circuit-breaker suites from [ISSUE #7826][ISSUE #7760] Reuse Divide keys and enforce one recovery probe #7857 included), checkstyle clean.Notes
DividePluginon top of current master (the [ISSUE #7826][ISSUE #7760] Reuse Divide keys and enforce one recovery probe #7857 refactor is already merged here).Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true(module-scoped:shenyu-plugin-dividewith-am, 103 tests + checkstyle green).