dmsolr opened a new pull request, #7671:
URL: https://github.com/apache/shenyu/pull/7671

   Fixes #7646
   
   ## Motivation
   
   `NonCommittingMcpResponseDecorator` (the Streamable HTTP MCP variant) 
captured backend tool responses without any memory bound and with per-chunk 
UTF-8 decoding:
   
   - The whole result was accumulated in a `StringBuilder`, so peak memory grew 
with the upstream body size with no budget and no over-limit behaviour.
   - Each chunk was decoded via `new String(bytes, UTF_8)`, which corrupts 
multi-byte UTF-8 sequences that span chunk boundaries.
   
   The SSE variant `ShenyuMcpResponseDecorator` already solves both problems. 
This PR brings the Streamable HTTP path to parity instead of introducing new 
configuration (the existing 1 MiB constant already protects the sibling path).
   
   ## Changes
   
   - Accumulate raw bytes in a `ByteArrayOutputStream` and decode UTF-8 
**exactly once** at completion, preserving multi-byte characters across 
arbitrary chunk boundaries.
   - Enforce an explicit **1 MiB capture budget** with deterministic over-limit 
behaviour: further chunks are dropped and the response future is completed 
exceptionally (`IllegalStateException`) rather than returning a truncated 
result.
   - Always release the incoming `DataBuffer`, including the over-limit path.
   - Make future completion idempotent and share it across `writeWith` / 
`writeAndFlushWith` / `setComplete` via a single `finishResponse()`.
   
   Template semantics and result correlation are unchanged; the 
passthrough/zero-copy redesign was intentionally avoided since the future + 
template contract requires a complete result.
   
   ## Tests
   
   Added to `NonCommittingMcpResponseDecoratorTest`:
   - `testWriteWithPreservesUtf8AcrossChunkBoundaries` — a 3-byte character 
split across two buffers decodes correctly.
   - `testWriteWithExceedingCaptureLimitFailsDeterministically` — over-limit 
responses fail deterministically and still release the buffer.
   
   Existing success / upstream-failure / cancellation buffer-release tests 
continue to pass. Full module suite green: `shenyu-plugin-mcp-server` 131 
tests, `shenyu-web` 96 tests.
   
   Make sure that:
   
   - [x] You have read the [contribution 
guidelines](https://shenyu.apache.org/community/contributor-guide).
   - [x] You submit test cases (unit or integration tests) that back your 
changes.
   - [x] Your local test passed `./mvnw clean install 
-Dmaven.javadoc.skip=true`.


-- 
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]

Reply via email to