From 5964273cc4354b7378b8bdf49fe455d2b46d7c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 26 Mar 2018 18:49:09 +0200 Subject: Fix the flushing of messages when switching to Websocket We now flush messages that are specific to cowboy_http only. Stream handlers should also flush their own specific messages if necessary, although timeouts will be flushed regardless of where they originate from. Also renames the http_SUITE to old_http_SUITE to distinguish new tests from old tests. Most old tests need to be removed or converted eventually as they're legacy tests from Cowboy 1.0. --- src/cowboy_http.erl | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/cowboy_http.erl') diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl index 2f30279..b6cb7a4 100644 --- a/src/cowboy_http.erl +++ b/src/cowboy_http.erl @@ -1004,7 +1004,7 @@ commands(State0=#state{ref=Ref, parent=Parent, socket=Socket, transport=Transpor stream_call_terminate(StreamID, switch_protocol, StreamState), %% Terminate children processes and flush any remaining messages from the mailbox. cowboy_children:terminate(Children), - flush(), + flush(Parent), %% @todo This is no good because commands return a state normally and here it doesn't %% we need to let this module go entirely. Perhaps it should be handled directly in %% cowboy_clear/cowboy_tls? @@ -1030,8 +1030,19 @@ headers_to_list(Headers0=#{<<"set-cookie">> := SetCookies}) -> headers_to_list(Headers) -> maps:to_list(Headers). -flush() -> - receive _ -> flush() after 0 -> ok end. +%% Flush messages specific to cowboy_http before handing over the +%% connection to another protocol. +flush(Parent) -> + receive + {timeout, _, _} -> + flush(Parent); + {{Pid, _}, _} when Pid =:= self() -> + flush(Parent); + {'EXIT', Pid, _} when Pid =/= Parent -> + flush(Parent) + after 0 -> + ok + end. %% @todo In these cases I'm not sure if we should continue processing commands. maybe_terminate(State=#state{last_streamid=StreamID}, StreamID, _Tail) -> -- cgit v1.2.3