Closed tony612 closed 4 years ago
Yeah it should not enter this clause when it's trailers, so it's missing a condition:
https://github.com/ninenines/cowlib/blob/master/src/cow_http2_machine.erl#L1197
I printed the window sizes:
StreamWindow: 0, ConnWindow: 46275 MinSendSize: 16384, SendSize: 388623
Sizes don't matter when it's trailers.
But from these code https://github.com/ninenines/cowlib/blob/master/src/cow_http2_machine.erl#L1187-L1191
SendSize = BufferSize + case DataOrFileOrTrailers of
{data, D} -> iolist_size(D);
#sendfile{bytes=B} -> B;
{trailers, _} -> 0
end,
When it's a trailers frame, the SendSize
is BufferSize + 0
, so if there are data frames in queue, the current SendSize
will still be large. I guess that's why I enter this clause?
It's just there so it doesn't crash. The if
needs to not enter the clause if sending trailers, because they are queued or sent here: https://github.com/ninenines/cowlib/blob/master/src/cow_http2_machine.erl#L1291
I didn't get it. The fact is the wrong clause is entered. Maybe we should change https://github.com/ninenines/cowlib/blob/master/src/cow_http2_machine.erl#L1187-L1191 from
SendSize = BufferSize + case DataOrFileOrTrailers of
{data, D} -> iolist_size(D);
#sendfile{bytes=B} -> B;
{trailers, _} -> 0
end,
to
SendSize = case DataOrFileOrTrailers of
{data, D} -> BufferSize + iolist_size(D);
#sendfile{bytes=B} -> BufferSize + B;
{trailers, _} -> 0
end,
if (element(1, DataOrFileOrTrailers) =/= trailers) andalso (StreamWindow < MinSendSize) andalso ...
Yeah. This is indeed a solution.
Anyway a test is necessary.
How to add a test for in cowlib
? I didn't see test cases like that in cowboy
. Is there a reference/guide?
Probably somewhere around here, just gotta adjust sizes and/or timings I suppose? Maybe stream_body_large
should stream a larger body. https://github.com/ninenines/cowboy/blob/master/test/req_SUITE.erl#L1061
Thanks!
The syntax is Elixir, but similar with Erlang. cowlib version: 2.8.0