aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-03-26 18:49:09 +0200
committerLoïc Hoguin <[email protected]>2018-03-26 18:53:07 +0200
commit5964273cc4354b7378b8bdf49fe455d2b46d7c3b (patch)
tree38194d0ae9a16056fff8e1c062fe6c6267d2d24c /src
parent4d5174632cc1feac541697b18e6fbbdd0eed021b (diff)
downloadcowboy-5964273cc4354b7378b8bdf49fe455d2b46d7c3b.tar.gz
cowboy-5964273cc4354b7378b8bdf49fe455d2b46d7c3b.tar.bz2
cowboy-5964273cc4354b7378b8bdf49fe455d2b46d7c3b.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http.erl17
1 files changed, 14 insertions, 3 deletions
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) ->