cloudbase-ai opened a new pull request, #7899: URL: https://github.com/apache/shenyu/pull/7899
Fixes #5396. When a plugin rewrites a request body and a later plugin returns without reading it, `ServerWebExchangeUtils.rewriteRequestBody` leaves an encoded pooled buffer unreleased. `BodyInserters.fromValue(String)` uses Spring's Mono-body optimization: it encodes the String while inserting to calculate content length, before the decorated request body is subscribed. The helper's error cleanup does not run on a successful short-circuit. Re-reading the decorated body can also reuse an already released buffer. Use `BodyInserters.fromPublisher(Flux.just(body), String.class)` so encoding happens only when the downstream subscribes and requests the body. `RequestDecorator` already removes content length and uses chunked headers, so it does not need the eager length calculation. Keep the existing codecs, media type/charset context, conversion timing and headers. Each body subscription encodes a fresh buffer without rerunning the conversion function. The production change is one inserter substitution, one import and its rationale comment; no new dependencies or cleanup abstraction. Validation on Java 17 with the Maven wrapper: - Before the fix, the 11 pooled-buffer regression cases had two assertion failures (short-circuit and cancellation before body demand) and one `IllegalReferenceCountException` on a repeated read. All 11 now pass. Normal forwarding, UTF-8/UTF-16LE/ISO-8859-1, headers, empty input/output, conversion errors and cancellation after consumption are covered with a real PooledByteBufAllocator and explicit reference-count assertions. - A separate local Reactor HTTP server smoke test sent 100 POST requests through the actual rewrite helper and then returned 403 without reading the rewritten body. The unmodified master helper allocated and retained 100 output buffers at reference count 1; the fixed helper allocated and retained zero. The test explicitly released the baseline's retained buffers afterward. This is a deterministic ownership check, not a production heap-growth or throughput benchmark. - Base plus all direct consumer modules (sign, cryptor, AI prompt, AI sensitive-word, AI request transformer) and their dependency reactor: **1,207 tests, 0 failures, 0 errors, 5 skipped**. Checkstyle, Apache RAT and `git diff --check` pass. Independent review found no blocking issue. ```sh ./mvnw -B -ntp -pl \ shenyu-plugin/shenyu-plugin-base,shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign,shenyu-plugin/shenyu-plugin-security/shenyu-plugin-cryptor,shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-prompt,shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-sensitive-word,shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-request-transformer \ -am test apache-rat:check -DskipRemoteResources=true \ -Djacoco.skip=true -Dmaven.javadoc.skip=true ``` The fix targets the shared request-rewrite path shown in #5396. Buffers already delivered to a downstream consumer remain that consumer's responsibility to release. The wire test uses the actual helper in a local WebFlux/Reactor HTTP pipeline; a full Bootstrap/configuration-sync Docker matrix was not run. - [x] Follow the contribution guidelines and DCO sign-off. - [x] Add regressions and verify the direct-consumer reactor above. - [ ] Full-repository clean install (the affected reactor was verified). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
