From 073c481656915f5c9c61f6ecea15a1754469a1f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 4 Feb 2025 12:12:49 +0100 Subject: HTTP/1: Ensure active mode is enabled for the next stream In rare cases it was possible for active mode to be disabled when there were no streams pipelined. This resulted in the dropping of the connection due to timeouts as no data could be received. We now enable active mode when necessary even if there are no streams pipelined. This was found while benchmarking and I have not been able to extract a test case. --- src/cowboy_http.erl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl index de268a6..c1c4b8d 100644 --- a/src/cowboy_http.erl +++ b/src/cowboy_http.erl @@ -1392,23 +1392,24 @@ stream_terminate(State0=#state{opts=Opts, in_streamid=InStreamID, in_state=InSta end. stream_next(State0=#state{opts=Opts, active=Active, out_streamid=OutStreamID, streams=Streams}) -> + %% Enable active mode again if it was disabled. + State1 = case Active of + true -> State0; + false -> active(State0) + end, NextOutStreamID = OutStreamID + 1, case lists:keyfind(NextOutStreamID, #stream.id, Streams) of false -> - State = State0#state{out_streamid=NextOutStreamID, out_state=wait}, + State = State1#state{out_streamid=NextOutStreamID, out_state=wait}, %% There are no streams remaining. We therefore can %% and want to switch back to the request_timeout. set_timeout(State, request_timeout); #stream{queue=Commands} -> - State = case Active of - true -> State0; - false -> active(State0) - end, %% @todo Remove queue from the stream. %% We set the flow to the initial flow size even though %% we might have sent some data through already due to pipelining. Flow = maps:get(initial_stream_flow_size, Opts, 65535), - commands(State#state{flow=Flow, out_streamid=NextOutStreamID, out_state=wait}, + commands(State1#state{flow=Flow, out_streamid=NextOutStreamID, out_state=wait}, NextOutStreamID, Commands) end. -- cgit v1.2.3