bhuvan-somisetty opened a new pull request, #13988:
URL: https://github.com/apache/apisix/pull/13988

   ### Description
   
   In `apisix/plugins/mcp-bridge.lua`, the event loop reads lines from the 
spawned process pipe via `proc:stdout_read_line()` and 
`proc:stderr_read_line()`. When a read timeout occurs mid-line, `ngx.pipe` 
returns `nil, "timeout", partial_data`.
   
   Previously, `line, _, stdout_partial = proc:stdout_read_line()` assigned the 
3rd return value to `stdout_partial` on every read. When the remaining portion 
of the line arrived in a subsequent iteration, `proc:stdout_read_line()` 
returned `line, nil, nil`, which immediately overwritten `stdout_partial` with 
`nil` before 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`:
   1. Accumulates partial stdout and stderr chunks across read timeouts 
(`stdout_partial = (stdout_partial or "") .. partial`).
   2. Slices and prepends any buffered partial data to the completed line upon 
a successful read before sending.
   3. Clears `stdout_partial` / `stderr_partial` only after successfully 
constructing the complete message.
   
   #### Which issue(s) this PR fixes:
   Fixes #13987
   
   ### Checklist
   
   - [x] I have explained the need for this PR and the problem it solves
   - [x] I have explained the changes or the new features added to this PR
   - [ ] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [x] I have verified that this change is backward compatible (If not, 
please discuss on the [APISIX mailing 
list](https://github.com/apache/apisix/tree/master#community) first)
   


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