fix(mcp-bridge): retain partial stdout and stderr across read timeouts - #13988
Open
bhuvan-somisetty wants to merge 1 commit into
Open
bhuvan-somisetty wants to merge 1 commit into
bhuvan-somisetty wants to merge 1 commit into
Conversation
When reading lines from the spawned MCP process via proc:stdout_read_line() and proc:stderr_read_line(), a read timeout sets the 3rd return value (partial data). On subsequent reads, the multiple assignment was overwriting the partial buffer with nil upon reading the remaining line, discarding the buffered data and sending truncated/corrupted payloads. Retain and accumulate partial stdout/stderr buffers across read timeouts, clearing them only after successfully joining with the completed line. Fixes apache#13987 Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In
apisix/plugins/mcp-bridge.lua, the event loop reads lines from the spawned process pipe viaproc:stdout_read_line()andproc:stderr_read_line(). When a read timeout occurs mid-line,ngx.pipereturnsnil, "timeout", partial_data.Previously,
line, _, stdout_partial = proc:stdout_read_line()assigned the 3rd return value tostdout_partialon every read. When the remaining portion of the line arrived in a subsequent iteration,proc:stdout_read_line()returnedline, nil, nil, which immediately overwrittenstdout_partialwithnilbefore the concatenation could happen. As a result, the buffered partial chunk was discarded and only the trailing fragment was dispatched to the MCP client.This change fixes partial chunk handling in
mcp-bridge:stdout_partial = (stdout_partial or "") .. partial).stdout_partial/stderr_partialonly after successfully constructing the complete message.Which issue(s) this PR fixes:
Fixes #13987
Checklist