Skip to content

Commit

Permalink
Don't swallow 'other' messages
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rnewson committed Sep 8, 2015
1 parent 952087e commit 61a65fe
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/mochiweb_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand All @@ -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
Expand Down

0 comments on commit 61a65fe

Please sign in to comment.