Repository navigation
Receive a stdio server message that arrives in several reads - #68
Open
skybleak333 wants to merge 1 commit into
Open
skybleak333 wants to merge 1 commit into
skybleak333 wants to merge 1 commit into
Conversation
receive() kept the part of a line that fgets() returned only within one call, and decoded any buffer ending with } or ], so a large response failed with a JsonException.
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.
Summary
The client's stdio transport now keeps the part of a server message that has arrived until its newline comes, so a large response is received whole.
Motivation
StdioTransportreads the server's stdout without blocking, and therefgets()also returns the part of a line that has arrived so far.receive()collected the chunks in a local$buffer, so a part read in one call was dropped when the pipe ran dry, and it decoded any buffer that ended with}or]. The rest of the message then arrived alone and failed to decode.With a stdio server whose tool returns a string of the requested length, and the SDK client calling it (
$client->connect()+callTool(), macOS, PHP 8.4):JsonException: Syntax errorreceive()now keeps the unfinished line in the read stream and decodes it once its newline arrives, which is how the stdio transport delimits messages. A last message without a trailing newline is still decoded when the server closes stdout.Type of change
Versioning impact
v1.7.X) — non-breaking bug fix or minor feature/improvementTest plan
composer checkpasses locallycomposer conformancepasses locally — not run: the suite drives the HTTP transport, this change is in the stdio oneStdioTransportPartialLineTeststarts a small PHP script as the server, which writes a response in two parts with a pause between them (both tests fail without the change)Compatibility
Documentation
CHANGELOG.mdunder[Unreleased]Additional notes
#66 fixes the same
fgets()behaviour on the server side. The two PRs touch different files, but both add a### Fixedsection under[Unreleased]in the changelog, so whichever lands second needs that merged; happy to rebase.