From 3d163136e59ed02719fe6dd5f57bbcd7a82d6fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sat, 5 Oct 2019 13:40:27 +0200 Subject: Make sure ensure_window doesn't crash if stream is closed --- src/cow_http2_machine.erl | 17 ++++++++++++----- 1 file 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. -- cgit v1.2.3