Browse Source

Make sure cowboy_http doesn't receive stray timeout messages

Loïc Hoguin 5 years ago
parent
commit
8f6ee9c186
1 changed files with 11 additions and 2 deletions
  1. 11 2
      src/cowboy_http.erl

+ 11 - 2
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}) ->
 cancel_timeout(State=#state{timer=TimerRef}) ->
 	ok = case TimerRef of
 	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,
 	end,
 	State#state{timer=undefined}.
 	State#state{timer=undefined}.