aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_http.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-10-22 14:53:04 +0100
committerLoïc Hoguin <[email protected]>2017-10-22 14:53:04 +0100
commit4bebe39975aab28962ac3850aa25a7d768c349bb (patch)
treea805886c2c37ed3c8827cb1572c194a8eba163cb /src/cowboy_http.erl
parentdebaecd49ae3efab4c319f3ec67677c82fe9e9a5 (diff)
downloadcowboy-4bebe39975aab28962ac3850aa25a7d768c349bb.tar.gz
cowboy-4bebe39975aab28962ac3850aa25a7d768c349bb.tar.bz2
cowboy-4bebe39975aab28962ac3850aa25a7d768c349bb.zip
Ensure stream terminate is called when switching protocols
Diffstat (limited to 'src/cowboy_http.erl')
-rw-r--r--src/cowboy_http.erl19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl
index 4ff9f8c..2ed0840 100644
--- a/src/cowboy_http.erl
+++ b/src/cowboy_http.erl
@@ -878,22 +878,17 @@ commands(State0=#state{ref=Ref, parent=Parent, socket=Socket, transport=Transpor
%% @todo This should be the last stream running otherwise we need to wait before switching.
%% @todo If there's streams opened after this one, fail instead of 101.
State = cancel_timeout(State0),
- %% @todo When we actually do the upgrade, we only have the one stream left, plus
- %% possibly some processes terminating. We need a smart strategy for handling the
- %% children shutdown. We can start with brutal_kill and discarding the EXIT messages
- %% received before switching to Websocket. Something better would be to let the
- %% stream processes finish but that implies the Websocket module to know about
- %% them and filter the messages. For now, kill them all and discard all messages
- %% in the mailbox.
-
+ %% Send a 101 response, then terminate the stream.
+ State = #state{streams=Streams} = commands(State, StreamID, [{inform, 101, Headers}]),
+ #stream{state=StreamState} = lists:keyfind(StreamID, #stream.id, Streams),
+ %% @todo We need to shutdown processes here first.
+ stream_call_terminate(StreamID, switch_protocol, StreamState),
+ %% Terminate children processes and flush any remaining messages from the mailbox.
cowboy_children:terminate(Children),
-
flush(),
- %% Everything good, upgrade!
- _ = commands(State, StreamID, [{inform, 101, Headers}]),
%% @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? Perhaps not. We do want that Buffer.
+ %% cowboy_clear/cowboy_tls?
Protocol:takeover(Parent, Ref, Socket, Transport, Opts, <<>>, InitialState);
%% Stream shutdown.
commands(State, StreamID, [stop|Tail]) ->