Skip to content

Fix plugin crash on large CodeGeneratorRequest input#20

Merged
kafkiansky merged 5 commits intothesis-php:0.1.xfrom
zlodes:fix/stdin-large-input
Mar 24, 2026
Merged

Fix plugin crash on large CodeGeneratorRequest input#20
kafkiansky merged 5 commits intothesis-php:0.1.xfrom
zlodes:fix/stdin-large-input

Conversation

@zlodes
Copy link
Contributor

@zlodes zlodes commented Mar 24, 2026

Summary

  • Replace amphp's non-blocking ByteStream\buffer(ByteStream\getStdin()) with synchronous stream_get_contents(STDIN) to prevent premature EOF detection on pipe reads exceeding ~250KB

Root cause

amphp's ReadableResourceStream sets STDIN to non-blocking mode and permanently closes the stream when feof() returns true — even transiently. On large pipe payloads that exceed the OS pipe buffer, fread() can drain the buffer faster than protoc writes, causing a spurious EOF. This is the same class of bug as amphp/byte-stream#47.

STDIN reading is inherently synchronous for protoc plugins (protoc sends the full request before expecting a response), so non-blocking I/O provides no benefit here.

Fixes #19

zlodes added 2 commits March 24, 2026 21:04
Replace amphp's non-blocking ByteStream\buffer(ByteStream\getStdin())
with synchronous stream_get_contents(STDIN) to prevent premature EOF
detection on pipe reads exceeding ~250KB.

amphp's ReadableResourceStream sets STDIN to non-blocking mode and
permanently closes the stream when feof() returns true — even
transiently. On large pipe payloads that exceed the OS pipe buffer,
fread() can drain the buffer faster than protoc writes, causing
a spurious EOF (see amphp/byte-stream#47).

Fixes thesis-php#19
@zlodes
Copy link
Contributor Author

zlodes commented Mar 24, 2026

@kafkiansky additionally we can use native functions in \Thesis\Protoc\Io\WriteStreamOutput and then completely remove amphp/byte-stream dependency. :)

@kafkiansky
Copy link
Contributor

Thank you, @zlodes

@kafkiansky kafkiansky merged commit 411b64c into thesis-php:0.1.x Mar 24, 2026
10 checks passed
@zlodes zlodes deleted the fix/stdin-large-input branch March 24, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugin crashes (exit 255) when CodeGeneratorRequest exceeds ~250KB

2 participants