diff options
author | Loïc Hoguin <[email protected]> | 2020-07-03 11:02:59 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2020-07-03 11:02:59 +0200 |
commit | 03d306e6d172eb272a564aa8626d4554d1046455 (patch) | |
tree | 35d3f8f9bd585e3e46aa55810019a8314a6a8b62 | |
parent | 5aac00d60c7f22d717375e45a69769f53ad9555c (diff) | |
download | cowboy-03d306e6d172eb272a564aa8626d4554d1046455.tar.gz cowboy-03d306e6d172eb272a564aa8626d4554d1046455.tar.bz2 cowboy-03d306e6d172eb272a564aa8626d4554d1046455.zip |
Fix concurrent body streaming getting stuck with HTTP/2
-rw-r--r-- | src/cowboy_stream_h.erl | 8 | ||||
-rw-r--r-- | test/req_SUITE.erl | 10 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/cowboy_stream_h.erl b/src/cowboy_stream_h.erl index 9f42acc..a4a1c1a 100644 --- a/src/cowboy_stream_h.erl +++ b/src/cowboy_stream_h.erl @@ -235,9 +235,13 @@ info(StreamID, Data0={data, Pid, _, _}, State0=#state{stream_body_status=Status} end, Data = erlang:delete_element(2, Data0), do_info(StreamID, Data, [Data], State); -info(StreamID, Alarm={alarm, Name, on}, State) +info(StreamID, Alarm={alarm, Name, on}, State0=#state{stream_body_status=Status}) when Name =:= connection_buffer_full; Name =:= stream_buffer_full -> - do_info(StreamID, Alarm, [], State#state{stream_body_status=blocking}); + State = case Status of + normal -> State0#state{stream_body_status=blocking}; + _ -> State0 + end, + do_info(StreamID, Alarm, [], State); info(StreamID, Alarm={alarm, Name, off}, State=#state{stream_body_pid=Pid, stream_body_status=Status}) when Name =:= connection_buffer_full; Name =:= stream_buffer_full -> _ = case Status of diff --git a/test/req_SUITE.erl b/test/req_SUITE.erl index 8216a95..352b2a0 100644 --- a/test/req_SUITE.erl +++ b/test/req_SUITE.erl @@ -1012,6 +1012,16 @@ stream_body_content_length_nofin_error(Config) -> ok end. +stream_body_concurrent(Config) -> + ConnPid = gun_open(Config), + Ref1 = gun:get(ConnPid, "/resp/stream_body/loop", [{<<"accept-encoding">>, <<"gzip">>}]), + Ref2 = gun:get(ConnPid, "/resp/stream_body/loop", [{<<"accept-encoding">>, <<"gzip">>}]), + {response, nofin, 200, _} = gun:await(ConnPid, Ref1, infinity), + {ok, _} = gun:await_body(ConnPid, Ref1, infinity), + {response, nofin, 200, _} = gun:await(ConnPid, Ref2, infinity), + {ok, _} = gun:await_body(ConnPid, Ref2, infinity), + gun:close(ConnPid). + %% @todo Crash when calling stream_body after the fin flag has been set. %% @todo Crash when calling stream_body after calling reply. %% @todo Crash when calling stream_body before calling stream_reply. |