From 61a65fea7d6b1e9f93c4a2c6b96e96dee02bec6e Mon Sep 17 00:00:00 2001 From: Robert Newson Date: Tue, 8 Sep 2015 10:39:48 +0100 Subject: [PATCH] Don't swallow 'other' messages Mochiweb handlers that use the message queue can sometimes find that mochiweb has swallowed messages, causing them to timeout or block for a reply that will never come. --- src/mochiweb_http.erl | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/mochiweb_http.erl b/src/mochiweb_http.erl index a9290a29..568019ff 100644 --- a/src/mochiweb_http.erl +++ b/src/mochiweb_http.erl @@ -99,9 +99,7 @@ request(Socket, Opts, Body) -> exit(normal); {ssl_closed, _} -> mochiweb_socket:close(Socket), - exit(normal); - Other -> - handle_invalid_msg_request(Other, Socket, Opts) + exit(normal) after ?REQUEST_RECV_TIMEOUT -> mochiweb_socket:close(Socket), exit(normal) @@ -129,7 +127,7 @@ headers(Socket, Opts, Request, Headers, Body, HeaderCount) -> {tcp_closed, _} -> mochiweb_socket:close(Socket), exit(normal); - Other -> + {tcp_error, _, emsgsize} = Other -> handle_invalid_msg_request(Other, Socket, Opts, Request, Headers) after ?HEADERS_RECV_TIMEOUT -> mochiweb_socket:close(Socket), @@ -143,10 +141,6 @@ call_body({M, F}, Req) -> call_body(Body, Req) -> Body(Req). --spec handle_invalid_msg_request(term(), term(), term()) -> no_return(). -handle_invalid_msg_request(Msg, Socket, Opts) -> - handle_invalid_msg_request(Msg, Socket, Opts, {'GET', {abs_path, "/"}, {0,9}}, []). - -spec handle_invalid_msg_request(term(), term(), term(), term(), term()) -> no_return(). handle_invalid_msg_request(Msg, Socket, Opts, Request, RevHeaders) -> case {Msg, r15b_workaround()} of