diff options
author | Loïc Hoguin <[email protected]> | 2017-11-13 18:03:25 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2017-11-13 18:03:25 +0100 |
commit | 6a8f9ebbb27147548356be888e07372245340b20 (patch) | |
tree | aee14002af66e798ba94129fb03e95cb3b1e6423 | |
parent | 56dc5673d06e523a69c5b8b830f4d5462580e772 (diff) | |
download | cowboy-6a8f9ebbb27147548356be888e07372245340b20.tar.gz cowboy-6a8f9ebbb27147548356be888e07372245340b20.tar.bz2 cowboy-6a8f9ebbb27147548356be888e07372245340b20.zip |
Fix packet being dropped when using switch_protocol
This only happens if the switch takes too long, and should not
happen unless a spawned process refuses to shut down immediately.
-rw-r--r-- | src/cowboy_http.erl | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl index c681154..e287edc 100644 --- a/src/cowboy_http.erl +++ b/src/cowboy_http.erl @@ -916,6 +916,13 @@ 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), + %% Before we send the 101 response we need to stop receiving data + %% from the socket, otherwise the data might be receive before the + %% call to flush/0 and we end up inadvertently dropping a packet. + %% + %% @todo Handle cases where the request came with a body. We need + %% to process or skip the body before the upgrade can be completed. + Transport:setopts(Socket, [{active, false}]), %% Send a 101 response, then terminate the stream. #state{streams=Streams} = info(State, StreamID, {inform, 101, Headers}), #stream{state=StreamState} = lists:keyfind(StreamID, #stream.id, Streams), |