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

Add initial support for system messages in cowboy_loop

This commit is contained in:
Loïc Hoguin 2018-03-23 18:33:16 +01:00
parent 21c9c66971
commit 4d5174632c
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
3 changed files with 38 additions and 7 deletions

View file

@ -10,7 +10,7 @@
init(Req, _) ->
process_flag(trap_exit, true),
erlang:send_after(500, self(), timeout),
{cowboy_loop, Req, undefined, hibernate}.
{cowboy_loop, Req, undefined}.
info(timeout, Req, State) ->
%% Send an unused status code to make sure there's no
@ -19,5 +19,5 @@ info(timeout, Req, State) ->
info(_, Req, State) ->
{ok, Req, State}.
terminate({crash, _, _}, _, _) ->
terminate(_, _, _) ->
ok.

View file

@ -400,9 +400,8 @@ trap_exit_parent_exit_loop(Config) ->
Parent = do_get_remote_pid_tcp(Socket),
[{_, Pid, _, _}] = supervisor:which_children(Parent),
Pid ! {'EXIT', Parent, shutdown},
%% We're getting a 500 because the process exited in an unexpected way
%% from Cowboy's point of view.
{ok, "HTTP/1.1 500 "} = gen_tcp:recv(Socket, 13, 1000),
%% We exit normally but didn't send a response.
{ok, "HTTP/1.1 204 "} = gen_tcp:recv(Socket, 13, 1000),
false = is_process_alive(Pid),
ok.
@ -483,7 +482,7 @@ trap_exit_other_exit_loop(Config) ->
timer:sleep(100),
Parent = do_get_remote_pid_tcp(Socket),
[{_, Pid, _, _}] = supervisor:which_children(Parent),
Pid ! {'EXIT', Parent, shutdown},
Pid ! {'EXIT', self(), shutdown},
%% The process stays alive.
{ok, "HTTP/1.1 299 "} = gen_tcp:recv(Socket, 13, 1000),
true = is_process_alive(Pid),