p5-Protocol-HTTP2
p5-Protocol-HTTP2 copied to clipboard
Protocol::HTTP2::Client on_done gives undef header/content when tried with multiple streams
Hi, When I use Protocol::HTTP2::Client with request sent with multiple parallel requests(streams), the on_done() cb is returning undef values for header, content for all streams exept the last one(for which it returns valid data.). my code snippet: $self->client->request( %$req, on_done => sub { my ($header, $content) = @; $msg = "_make_next_client_request::on_done!!!!!!!!!!!!!!!!!!!!!!!!!!"; warn Dumper($msg); warn Dumper($header); warn Dumper($content);
Note that I send more than one(4) requests using above code and then wait for responses using below code: while ( $self->{'resp_revcd'} == 0 ) { $self->{_io}->can_read; while ( sysread $self->_socket, my $data, 4096 ) { $self->_client->feed($data); my $msg = "Recvd Response!!!!!!!!!!!!!!!!!!!!!!!"; warn Dumper($msg); warn Dumper($data);
I could see that for all streams created(using request()), the response frames are received nd on_done() is called. Also the streams is correctly getting closed.
ouput for all streams(except first): $VAR1 = 'Stream 7 changed state from HALF_CLOSED to CLOSED'; $VAR1 = '_make_next_client_request::on_done!!!!!!!!!!!!!!!!!!!!!!!!!!'; $VAR1 = undef; $VAR1 = undef;
output for first stream: $VAR1 = 'Stream 1 changed state from HALF_CLOSED to CLOSED'; $VAR1 = '_make_next_client_request::on_done!!!!!!!!!!!!!!!!!!!!!!!!!!'; $VAR1 = [ ':status', '410', 'xxxxx-xxx', 'dddddddddddddddddddddddddddd' ]; $VAR1 = '{"rrrrrrrr":"aaaaaaaaaaaaaaaa","timestamp":111111111111111111111111}';
Hi.
request() method doesn't send request (just prepare it and add to internal queue). To send/receive frames you need to write/read frames to/from socket, see example.
In your code snippet i see only sysread/feed pair, but no next_frame/syswrite.
I think you should understand that without syswrite, I can not send request. :). I know that request() does not send request. here goes the snippet for send: my $writer = $self->{_io}->can_write; while ( my $frame = $self->_client->next_frame ) { syswrite $self->_socket, $frame; warn Dumper("Sending Request!!!:: $frame "); }
My issue is not with send/receive, but when I send 4 requests in a go and get 4 responses back, I am getting only for the last response's header, content in 'on_done' cb. This must be due to overwriting by internal buffer I guess, but I could not find any documentation to this.
I cant guess what code you are using. I've created test script with 4 parallel requests and can't reproduce issue.
Hi, I am not sure the reason, and I do not have exact code now with me. I added changes to handle non-blocking socket read/write. I do not see this happening now. If I get time and could get same issue, I will post it then.