Event stream decoder drops the final event when reading it reaches EOF
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- Mezza giornata
- Idoneità per principianti
- 62/100
Direzione di ricerca
Start with valid() in the NonSeekableStreamDecodingEventStreamIterator class, which currently checks the stream's EOF state after the event is parsed. Run the reproduction in the issue against a BufferStream holding one event frame; it should print int(1) once the fix is in. Done means the final event is yielded even when the read hits EOF, and the existing decoder tests still pass. A test using BufferStream rather than php://temp would cover the regression.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
NonSeekableStreamDecodingEventStreamIterator drops the final event when reading it also reaches the end of the stream. If the stream contains just one event, nothing is returned.
valid() checks the stream’s EOF state after the event has already been parsed, so it can return false even though there’s a complete event ready to yield.
Expected Behavior
I think the decoder should still yield the last complete event, even if reading it reached the end of the stream.
Current Behavior
The example below prints int(0) instead of int(1). No exception is thrown.
Reproduction Steps
This example doesn’t need an AWS account or make any network requests.
Install aws/aws-sdk-php version 3.399.2, then run:
<?php
require 'vendor/autoload.php';
use Aws\Api\Parser\NonSeekableStreamDecodingEventStreamIterator;
use GuzzleHttp\Psr7\BufferStream;
$headers = '';
foreach ([
':message-type' => 'event',
':event-type' => 'messageStop',
':content-type' => 'application/json',
] as $name => $value) {
$headers .= chr(strlen($name)).$name.chr(7)
.pack('n', strlen($value)).$value;
}
$payload = '{"stopReason":"end_turn"}';
$prelude = pack('NN', 16 + strlen($headers) + strlen($payload), strlen($headers));
$frame = $prelude.hash('crc32b', $prelude, true).$headers.$payload;
$frame .= hash('crc32b', $frame, true);
$stream = new BufferStream;
$stream->write($frame);
$iterator = new NonSeekableStreamDecodingEventStreamIterator($stream);
var_dump(count(iterator_to_array($iterator)));
Possible Solution
Have valid() check whether there’s a parsed event available, rather than whether the underlying stream has reached EOF.
Additional Information/Context
I also reproduced this through BedrockRuntimeClient::converseStream() using a local HTTP server. It sent messageStop followed by metadata, but only messageStop was returned. Bedrock sends token usage in that final metadata event. ConverseStream documentation.
The existing decoder tests use a php://temp body, which only reports EOF after another read is attempted. BufferStream reports EOF as soon as its last byte is read, exposing the problem.
The same valid() implementation is still present on master. This is separate from #3371; #3373 changes the same decoder to address partial checksum reads.
SDK version used
3.399.2
Environment details
PHP 8.4.25, Ubuntu 24.04.
Generated by Codex, and reviewed by @binaryfire.
- Lingua principale
- PHP
- Stelle
- 6.2k
- Fork
- 1.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 10
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di aws/aws-sdk-php
-
feature-request needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
aws/aws-sdk-php#3365 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 Mezza giornata Idoneità per principianti 45/100
aws/aws-sdk-php#3377 ·
I maintainer di solito rispondono entro 1 giorno
-
Event stream decoder reports a checksum mismatch when the checksum is read in partsForse già presa @lazerg l’ha presa 7 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 25/100
aws/aws-sdk-php#3371 ·
I maintainer di solito rispondono entro 1 giorno
-
AssumeRoleCredentialProvider replaces non-RuntimeException failures with TypeErrorForse già presa @stobrien89 l’ha presa oggi. Apertabug pending-release
Difficoltà 2/5 1-3 ore Idoneità per principianti 25/100
aws/aws-sdk-php#3370 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
announcement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 12/100
aws/aws-sdk-php#3369 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di aws/aws-sdk-php
Issue simili
-
loginWithCustomTokenExchange() fails when an organization is configuredForse già presa @awss1i l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
auth0/auth0-PHP#883 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
type/bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
flarum/framework#5231 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
major-release
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 67/100
Intervention/image#1553 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
omegaup/omegaup#10353 · 1 commento ·
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 61/100