0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-16 05:00:24 +00:00

Exit gracefully on parent exit/sys:terminate/2,3

This commit is contained in:
Loïc Hoguin 2018-10-28 10:20:43 +01:00
parent 21ff3ff256
commit d4129e6305
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
5 changed files with 11 additions and 17 deletions

View file

@ -209,8 +209,7 @@ loop(State=#state{parent=Parent, socket=Socket, transport=Transport, opts=Opts,
loop(State, Buffer);
%% System messages.
{'EXIT', Parent, Reason} ->
%% @todo We should exit gracefully, if possible.
exit(Reason);
terminate(State, {stop, {exit, Reason}, 'Parent process terminated.'});
{system, From, Request} ->
sys:handle_system_msg(Request, From, Parent, ?MODULE, [], {State, Buffer});
%% Messages pertaining to a stream.
@ -1379,8 +1378,7 @@ system_continue(_, _, {State, Buffer}) ->
-spec system_terminate(any(), _, _, {#state{}, binary()}) -> no_return().
system_terminate(Reason, _, _, {State, _}) ->
%% @todo We should exit gracefully, if possible.
terminate(State, Reason).
terminate(State, {stop, {exit, Reason}, 'sys:terminate/2,3 was called.'}).
-spec system_code_change(Misc, _, _, _) -> {ok, Misc} when Misc::{#state{}, binary()}.
system_code_change(Misc, _, _, _) ->

View file

@ -165,8 +165,7 @@ loop(State=#state{parent=Parent, socket=Socket, transport=Transport,
terminate(State, {socket_error, Reason, 'An error has occurred on the socket.'});
%% System messages.
{'EXIT', Parent, Reason} ->
%% @todo We should exit gracefully.
exit(Reason);
terminate(State, {stop, {exit, Reason}, 'Parent process terminated.'});
{system, From, Request} ->
sys:handle_system_msg(Request, From, Parent, ?MODULE, [], {State, Buffer});
%% Timeouts.
@ -239,7 +238,6 @@ frame(State=#state{http2_machine=HTTP2Machine0}, Frame) ->
{stop, Frame, 'Client is going away.'});
{send, SendData, HTTP2Machine} ->
send_data(maybe_ack(State#state{http2_machine=HTTP2Machine}, Frame), SendData);
%% @todo Yeah StreamID would be better out of this, {error, StreamID, Tuple, State}
{error, {stream_error, StreamID, Reason, Human}, HTTP2Machine} ->
stream_reset(State#state{http2_machine=HTTP2Machine},
StreamID, {stream_error, Reason, Human});
@ -591,8 +589,6 @@ send_response(State0, StreamID, StatusCode, Headers, Body) ->
end,
case Size of
0 ->
%% @todo If IsFin=fin, we may want to skip the body and terminate the stream,
%% if we are no longer tracking the stream.
State = send_headers(State0, StreamID, fin, StatusCode, Headers),
maybe_terminate_stream(State, StreamID, fin);
_ ->
@ -783,8 +779,7 @@ system_continue(_, _, {State, Buffer}) ->
-spec system_terminate(any(), _, _, {#state{}, binary()}) -> no_return().
system_terminate(Reason, _, _, {State, _}) ->
%% @todo We should exit gracefully, if possible.
terminate(State, Reason).
terminate(State, {stop, {exit, Reason}, 'sys:terminate/2,3 was called.'}).
-spec system_code_change(Misc, _, _, _) -> {ok, Misc} when Misc::{#state{}, binary()}.
system_code_change(Misc, _, _, _) ->

View file

@ -50,7 +50,7 @@
| {socket_error, closed | atom(), human_reason()}
| {stream_error, cow_http2:error(), human_reason()}
| {connection_error, cow_http2:error(), human_reason()}
| {stop, cow_http2:frame(), human_reason()}.
| {stop, cow_http2:frame() | {exit, any()}, human_reason()}.
-export_type([reason/0]).
-type partial_req() :: map(). %% @todo Take what's in cowboy_req with everything? optional.