aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBartek Walkowicz <[email protected]>2018-03-01 14:49:57 +0100
committerLoïc Hoguin <[email protected]>2018-03-14 17:15:06 +0100
commit21317093285190f854acaf223db2e08f79069757 (patch)
treee234a0e8e32b39f87bdfc2282b09611d71a55fc8 /src
parentf9092126fafe063513444ca2b3c2aec6af14ed7b (diff)
downloadcowboy-21317093285190f854acaf223db2e08f79069757.tar.gz
cowboy-21317093285190f854acaf223db2e08f79069757.tar.bz2
cowboy-21317093285190f854acaf223db2e08f79069757.zip
Add case for handling infinity for idle/request_timeout
Currently cowboy assumes that idle_timeout or request_timeout is a number and always starts timers. Similar situation takes place in case of preface_timeout for http2. This commit adds case for handling infinity as a timeout, allowing to not start mentioned timers.
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http.erl6
-rw-r--r--src/cowboy_http2.erl13
2 files changed, 13 insertions, 6 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl
index 6a75a1a..2f30279 100644
--- a/src/cowboy_http.erl
+++ b/src/cowboy_http.erl
@@ -222,8 +222,10 @@ set_timeout(State0=#state{opts=Opts, streams=Streams}) ->
[] -> {request_timeout, 5000};
_ -> {idle_timeout, 60000}
end,
- Timeout = maps:get(Name, Opts, Default),
- TimerRef = erlang:start_timer(Timeout, self(), Name),
+ TimerRef = case maps:get(Name, Opts, Default) of
+ infinity -> undefined;
+ Timeout -> erlang:start_timer(Timeout, self(), Name)
+ end,
State#state{timer=TimerRef}.
cancel_timeout(State=#state{timer=TimerRef}) ->
diff --git a/src/cowboy_http2.erl b/src/cowboy_http2.erl
index b21d6da..caa1f07 100644
--- a/src/cowboy_http2.erl
+++ b/src/cowboy_http2.erl
@@ -122,7 +122,7 @@
%% is established and continues normally. An exception is when a HEADERS
%% frame is sent followed by CONTINUATION frames: no other frame can be
%% sent in between.
- parse_state = undefined :: {preface, sequence, reference()}
+ parse_state = undefined :: {preface, sequence, undefined | reference()}
| {preface, settings, reference()}
| normal
| {continuation, cowboy_stream:streamid(), cowboy_stream:fin(), binary()},
@@ -203,8 +203,10 @@ preface(#state{socket=Socket, transport=Transport, next_settings=Settings}) ->
Transport:send(Socket, cow_http2:settings(Settings)).
preface_timeout(Opts) ->
- PrefaceTimeout = maps:get(preface_timeout, Opts, 5000),
- erlang:start_timer(PrefaceTimeout, self(), preface_timeout).
+ case maps:get(preface_timeout, Opts, 5000) of
+ infinity -> undefined;
+ PrefaceTimeout -> erlang:start_timer(PrefaceTimeout, self(), preface_timeout)
+ end.
%% @todo Add the timeout for last time since we heard of connection.
before_loop(State, Buffer) ->
@@ -305,7 +307,10 @@ parse(State=#state{local_settings=#{max_frame_size := MaxFrameSize},
end.
parse_settings_preface(State, Frame={settings, _}, Rest, TRef) ->
- _ = erlang:cancel_timer(TRef, [{async, true}, {info, false}]),
+ ok = case TRef of
+ undefined -> ok;
+ _ -> erlang:cancel_timer(TRef, [{async, true}, {info, false}])
+ end,
parse(frame(State#state{parse_state=normal}, Frame), Rest);
parse_settings_preface(State, _, _, _) ->
terminate(State, {connection_error, protocol_error,