aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBing Han <[email protected]>2018-07-05 00:32:07 +0800
committerLoïc Hoguin <[email protected]>2018-08-13 11:10:49 +0200
commite9fd2925ae6be7b6f456e86254b1437d06dfa973 (patch)
tree39f211031fc987a77481671be0034cd253721100
parentaee40d5bb599237fc159d6684fb308810ac465c3 (diff)
downloadcowboy-e9fd2925ae6be7b6f456e86254b1437d06dfa973.tar.gz
cowboy-e9fd2925ae6be7b6f456e86254b1437d06dfa973.tar.bz2
cowboy-e9fd2925ae6be7b6f456e86254b1437d06dfa973.zip
Fix cancelling undefined settings timer
when settings_timeout is infinity
-rw-r--r--src/cowboy_http2.erl5
-rw-r--r--test/http2_SUITE.erl17
2 files changed, 21 insertions, 1 deletions
diff --git a/src/cowboy_http2.erl b/src/cowboy_http2.erl
index 601ea98..5e72870 100644
--- a/src/cowboy_http2.erl
+++ b/src/cowboy_http2.erl
@@ -485,7 +485,10 @@ frame(State0=#state{socket=Socket, transport=Transport, opts=Opts,
%% Ack for a previously sent SETTINGS frame.
frame(State0=#state{local_settings=Local0, next_settings=NextSettings,
next_settings_timer=TRef}, settings_ack) ->
- ok = erlang:cancel_timer(TRef, [{async, true}, {info, false}]),
+ ok = case TRef of
+ undefined -> ok;
+ _ -> erlang:cancel_timer(TRef, [{async, true}, {info, false}])
+ end,
Local = maps:merge(Local0, NextSettings),
State1 = State0#state{local_settings=Local, next_settings=#{},
next_settings_timer=undefined},
diff --git a/test/http2_SUITE.erl b/test/http2_SUITE.erl
index e3dd4b2..b71b2c9 100644
--- a/test/http2_SUITE.erl
+++ b/test/http2_SUITE.erl
@@ -159,3 +159,20 @@ resp_iolist_body(Config) ->
{ok, RespBody} = gun:await_body(ConnPid, Ref),
Len = iolist_size(RespBody),
gun:close(ConnPid).
+
+settings_timeout_infinity(Config) ->
+ doc("Ensure infinity for settings_timeout is accepted."),
+ ProtoOpts = #{
+ env => #{dispatch => cowboy_router:compile(init_routes(Config))},
+ settings_timeout => infinity
+ },
+ {ok, Pid} = cowboy:start_clear(name(), [{port, 0}], ProtoOpts),
+ Ref = erlang:monitor(process, Pid),
+ Port = ranch:get_port(name()),
+ {ok, _} = do_handshake([{port, Port}|Config]),
+ receive
+ {'DOWN', Ref, process, Pid, Reason} ->
+ error(Reason)
+ after 1000 ->
+ cowboy:stop_listener(name())
+ end.