aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-10-06 14:41:03 +0200
committerLoïc Hoguin <[email protected]>2017-10-06 14:41:03 +0200
commitf4ad4c4742c76a5a100e13b07de7419cbc27dc6b (patch)
tree6f780aa681f54598c17bda7cb6efaf057b9d7ddc
parentb42c40225a6be792aa0706bdeefabc6691ae5c2d (diff)
downloadgun-f4ad4c4742c76a5a100e13b07de7419cbc27dc6b.tar.gz
gun-f4ad4c4742c76a5a100e13b07de7419cbc27dc6b.tar.bz2
gun-f4ad4c4742c76a5a100e13b07de7419cbc27dc6b.zip
Don't error out when the owner is gone normally
-rw-r--r--src/gun.erl9
-rw-r--r--test/gun_SUITE.erl4
2 files changed, 9 insertions, 4 deletions
diff --git a/src/gun.erl b/src/gun.erl
index e9155b2..53a6c15 100644
--- a/src/gun.erl
+++ b/src/gun.erl
@@ -695,7 +695,7 @@ loop(State=#state{parent=Parent, owner=Owner, owner_ref=OwnerRef, host=Host, por
{'DOWN', OwnerRef, process, Owner, Reason} ->
Protocol:close(ProtoState),
Transport:close(Socket),
- error({owner_gone, Reason});
+ owner_gone(Reason);
{system, From, Request} ->
sys:handle_system_msg(Request, From, Parent, ?MODULE, [],
{loop, State});
@@ -764,7 +764,7 @@ ws_loop(State=#state{parent=Parent, owner=Owner, owner_ref=OwnerRef, socket=Sock
{'DOWN', OwnerRef, process, Owner, Reason} ->
Protocol:close(owner_gone, ProtoState),
Transport:close(Socket),
- error({owner_gone, Reason});
+ owner_gone(Reason);
{system, From, Request} ->
sys:handle_system_msg(Request, From, Parent, ?MODULE, [],
{ws_loop, State});
@@ -776,6 +776,11 @@ ws_loop(State=#state{parent=Parent, owner=Owner, owner_ref=OwnerRef, socket=Sock
error_logger:error_msg("Unexpected message: ~w~n", [Any])
end.
+owner_gone(normal) -> exit(normal);
+owner_gone(shutdown) -> exit(shutdown);
+owner_gone(Shutdown = {shutdown, _}) -> exit(Shutdown);
+owner_gone(Reason) -> error({owner_gone, Reason}).
+
system_continue(_, _, {retry_loop, State, Retry}) ->
retry_loop(State, Retry);
system_continue(_, _, {loop, State}) ->
diff --git a/test/gun_SUITE.erl b/test/gun_SUITE.erl
index a7e2169..9f003e8 100644
--- a/test/gun_SUITE.erl
+++ b/test/gun_SUITE.erl
@@ -57,7 +57,7 @@ detect_owner_gone(_) ->
end,
Ref = monitor(process, Pid),
receive
- {'DOWN', Ref, process, Pid, {{owner_gone, _}, _}} ->
+ {'DOWN', Ref, process, Pid, normal} ->
ok
after 1000 ->
true = erlang:is_process_alive(Pid),
@@ -86,7 +86,7 @@ detect_owner_gone_ws(_) ->
end,
Ref = monitor(process, Pid),
receive
- {'DOWN', Ref, process, Pid, {{owner_gone, _}, _}} ->
+ {'DOWN', Ref, process, Pid, normal} ->
ok
after 1000 ->
true = erlang:is_process_alive(Pid),