From 8f6ee9c1868ebc7bf31fb4846114919e164e0cf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 2 Oct 2019 16:57:22 +0200 Subject: Make sure cowboy_http doesn't receive stray timeout messages --- src/cowboy_http.erl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/cowboy_http.erl') diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl index a6c640a..6670781 100644 --- a/src/cowboy_http.erl +++ b/src/cowboy_http.erl @@ -267,8 +267,17 @@ set_timeout(State0=#state{opts=Opts, overriden_opts=Override, streams=Streams}) cancel_timeout(State=#state{timer=TimerRef}) -> ok = case TimerRef of - undefined -> ok; - _ -> erlang:cancel_timer(TimerRef, [{async, true}, {info, false}]) + undefined -> + ok; + _ -> + %% Do a synchronous cancel and remove the message if any + %% to avoid receiving stray messages. + erlang:cancel_timer(TimerRef), + receive + {timeout, TimerRef, _} -> ok + after 0 -> + ok + end end, State#state{timer=undefined}. -- cgit v1.2.3