From fd211d3c039e3521537087ef848727bb4f7410c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 2 Jan 2012 09:41:30 +0100 Subject: Fix handler crashes handling We try to send a 500 error only if we didn't send the response headers yet. If they were, then we have no way to be sure the response was fully sent, nor should we assume anything about how this will be handled client-side, so we do nothing more and in both cases close the connection. --- src/cowboy_http_websocket.erl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/cowboy_http_websocket.erl') diff --git a/src/cowboy_http_websocket.erl b/src/cowboy_http_websocket.erl index 058c843..0f0204c 100644 --- a/src/cowboy_http_websocket.erl +++ b/src/cowboy_http_websocket.erl @@ -169,6 +169,8 @@ websocket_handshake(State=#state{version=0, origin=Origin, {<<"Sec-Websocket-Location">>, Location}, {<<"Sec-Websocket-Origin">>, Origin}], Req#http_req{resp_state=waiting}), + %% Flush the resp_sent message before moving on. + receive {cowboy_http_req, resp_sent} -> ok after 0 -> ok end, %% We replied with a proper response. Proxies should be happy enough, %% we can now read the 8 last bytes of the challenge keys and send %% the challenge response directly to the socket. @@ -188,6 +190,8 @@ websocket_handshake(State=#state{challenge=Challenge}, [{<<"Upgrade">>, <<"websocket">>}, {<<"Sec-Websocket-Accept">>, Challenge}], Req#http_req{resp_state=waiting}), + %% Flush the resp_sent message before moving on. + receive {cowboy_http_req, resp_sent} -> ok after 0 -> ok end, handler_before_loop(State#state{messages=Transport:messages()}, Req2, HandlerState, <<>>). -- cgit v1.2.3