aboutsummaryrefslogtreecommitdiffstats
path: root/erts/preloaded
diff options
context:
space:
mode:
authorRaimo Niskanen <[email protected]>2013-06-15 14:02:04 +0200
committerRaimo Niskanen <[email protected]>2013-06-15 14:09:30 +0200
commitc1c942d22b8f668d7b70cfdbdc57c525d1c32883 (patch)
treeaef2530c8fd89178bfb03d445dd2fb24fe2df20f /erts/preloaded
parente0f1ba5c00cbe533404527942a6c8c500dca5aa7 (diff)
parentc7fed1781bec1fbc893931a4d732a38a55f9ceea (diff)
downloadotp-c1c942d22b8f668d7b70cfdbdc57c525d1c32883.tar.gz
otp-c1c942d22b8f668d7b70cfdbdc57c525d1c32883.tar.bz2
otp-c1c942d22b8f668d7b70cfdbdc57c525d1c32883.zip
Merge branch 'maint'
Conflicts: erts/preloaded/ebin/prim_inet.beam
Diffstat (limited to 'erts/preloaded')
-rw-r--r--erts/preloaded/ebin/prim_inet.beambin70216 -> 70520 bytes
-rw-r--r--erts/preloaded/src/prim_inet.erl28
2 files changed, 26 insertions, 2 deletions
diff --git a/erts/preloaded/ebin/prim_inet.beam b/erts/preloaded/ebin/prim_inet.beam
index 2db6a58d34..fb8321733a 100644
--- a/erts/preloaded/ebin/prim_inet.beam
+++ b/erts/preloaded/ebin/prim_inet.beam
Binary files differ
diff --git a/erts/preloaded/src/prim_inet.erl b/erts/preloaded/src/prim_inet.erl
index 36a650cb5c..fb1269cf91 100644
--- a/erts/preloaded/src/prim_inet.erl
+++ b/erts/preloaded/src/prim_inet.erl
@@ -177,8 +177,32 @@ close_pend_loop(S, N) ->
end.
close_port(S) ->
- catch erlang:port_close(S),
- receive {'EXIT',S,_} -> ok after 0 -> ok end.
+ case erlang:process_info(self(), trap_exit) of
+ {trap_exit,true} ->
+ %% Ensure exit message and consume it
+ link(S),
+ %% This is still not a perfect solution.
+ %%
+ %% The problem is to close the port and consume any exit
+ %% message while not knowing if this process traps exit
+ %% nor if this process has a link to the port. Here we
+ %% just knows that this process traps exit.
+ %%
+ %% If we right here get killed for some reason that exit
+ %% signal will propagate to the port and onwards to anyone
+ %% that is linked to the port. E.g when we close a socket
+ %% that is not ours.
+ %%
+ %% The problem can be solved with lists:member on our link
+ %% list but we deem that as potentially too expensive. We
+ %% need an is_linked/1 function or guard, or we need
+ %% a port_close function that can atomically unlink...
+ catch erlang:port_close(S),
+ receive {'EXIT',S,_} -> ok end;
+ {trap_exit,false} ->
+ catch erlang:port_close(S),
+ ok
+ end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%