aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-10-05 13:40:27 +0200
committerLoïc Hoguin <[email protected]>2019-10-05 13:40:27 +0200
commit3d163136e59ed02719fe6dd5f57bbcd7a82d6fef (patch)
tree8eba84ffb25bba0941c5dee53c1f796dcf428808
parentbd32d879e151ba6fa1732b4eee6cac064846e9cc (diff)
downloadcowlib-3d163136e59ed02719fe6dd5f57bbcd7a82d6fef.tar.gz
cowlib-3d163136e59ed02719fe6dd5f57bbcd7a82d6fef.tar.bz2
cowlib-3d163136e59ed02719fe6dd5f57bbcd7a82d6fef.zip
Make sure ensure_window doesn't crash if stream is closed
-rw-r--r--src/cow_http2_machine.erl17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/cow_http2_machine.erl b/src/cow_http2_machine.erl
index 68d361a..754b82b 100644
--- a/src/cow_http2_machine.erl
+++ b/src/cow_http2_machine.erl
@@ -1381,12 +1381,19 @@ ensure_window(Size, State=#http2_machine{opts=Opts, remote_window=RemoteWindow})
-spec ensure_window(cow_http2:streamid(), non_neg_integer(), State)
-> ok | {ok, pos_integer(), State} when State::http2_machine().
ensure_window(StreamID, Size, State=#http2_machine{opts=Opts}) ->
- Stream = #stream{remote_window=RemoteWindow} = stream_get(StreamID, State),
- case ensure_window(Size, RemoteWindow, stream, Opts) of
- ok ->
+ case stream_get(StreamID, State) of
+ %% For simplicity's sake, we do not consider attempts to ensure the window
+ %% of a terminated stream to be errors. We simply act as if the stream
+ %% window is large enough.
+ undefined ->
ok;
- {ok, Increment} ->
- {ok, Increment, stream_store(Stream#stream{remote_window=RemoteWindow + Increment}, State)}
+ Stream = #stream{remote_window=RemoteWindow} ->
+ case ensure_window(Size, RemoteWindow, stream, Opts) of
+ ok ->
+ ok;
+ {ok, Increment} ->
+ {ok, Increment, stream_store(Stream#stream{remote_window=RemoteWindow + Increment}, State)}
+ end
end.
%% No need to update the window when we are not expecting data.