From 5ffd705aed4d779b07c0913783f84abbdf643e16 Mon Sep 17 00:00:00 2001 From: Anton Zaets Date: Wed, 27 Dec 2017 17:09:24 +0300 Subject: [PATCH] Fixing of hanging after "exit" in process which is linked to handler process Problem statement: Request handler start linked process, which is finishing with exit(Reason). In such case the `info` function clause for error handling will never be called and default clause will be called instead. This causes hanging of cowboy. The typical situation is starting gen_server from request handler. If gen_server returns {stop, Reason} after error in initialisation then otp calls `exit(Reason)` internally. The solution: New `info` clause for error without stacktrace. --- src/cowboy_stream_h.erl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cowboy_stream_h.erl b/src/cowboy_stream_h.erl index 5c674dde6..a8a94529c 100644 --- a/src/cowboy_stream_h.erl +++ b/src/cowboy_stream_h.erl @@ -101,6 +101,12 @@ info(StreamID, Exit = {'EXIT', Pid, {Reason, Stacktrace}}, State=#state{ref=Ref, {error_response, 500, #{<<"content-length">> => <<"0">>}, <<>>}, {internal_error, Exit, 'Stream process crashed.'} ], State}; +info(StreamID, Exit = {'EXIT', Pid, Reason}, State=#state{ref=Ref, pid=Pid}) -> + report_crash(Ref, StreamID, Pid, Reason, []), + {[ + {error_response, 500, #{<<"content-length">> => <<"0">>}, <<>>}, + {internal_error, Exit, 'Stream process crashed.'} + ], State}; %% Request body, body buffered large enough or complete. info(_StreamID, {read_body, Ref, Length, _}, State=#state{pid=Pid, read_body_is_fin=IsFin, read_body_buffer=Buffer, body_length=BodyLen})