[erlang-questions] gen_udp port leaking after controlling_process(Port, self())

Ahmed Omar spawn.think@REDACTED
Wed Apr 27 20:31:55 CEST 2011


Nice catch, so something like this shall fix it
diff --git a/lib/kernel/src/inet.erl b/lib/kernel/src/inet.erl
index 327e0f9..8a9b1ab 100644
--- a/lib/kernel/src/inet.erl
+++ b/lib/kernel/src/inet.erl
@@ -1262,6 +1262,8 @@ udp_close(S) when is_port(S) ->
 %% Set controlling process for TCP socket.
 tcp_controlling_process(S, NewOwner) when is_port(S), is_pid(NewOwner) ->
     case erlang:port_info(S, connected) of
+       {connected, NewOwner}->
+            ok;
        {connected, Pid} when Pid =/= self() ->
            {error, not_owner};
        undefined ->
@@ -1313,6 +1315,8 @@ tcp_sync_input(S, Owner, Flag) ->
 %% Set controlling process for UDP or SCTP socket.
 udp_controlling_process(S, NewOwner) when is_port(S), is_pid(NewOwner) ->
     case erlang:port_info(S, connected) of
+       {connected, NewOwner}->
+            ok;
        {connected, Pid} when Pid =/= self() ->
            {error, not_owner};
        _ ->


On Wed, Apr 27, 2011 at 7:36 PM, Tony Rogvall <tony@REDACTED> wrote:

> Nice ! ;-)
>
> Same problem with gen_tcp !
> You can use inet:i() to verify that even Erlang knows about the problem :-)
>
> I see the problem.  inet:udp/tcp_controlling_process unlinks from the
> socket without
> checking that it is already the controlling process, effectively creating a
> zombie port.
>
> Work around: Do not change the controlling process to it self.
>
> /Tony
>
>
> On 27 apr 2011, at 19.05, Max Lapshin wrote:
>
> Open UDP port
>
> $ erl
> Erlang R14B02 (erts-5.8.3) [source] [64-bit] [smp:4:4] [rq:4]
> [async-threads:0] [hipe] [kernel-poll:false]
>
> Eshell V5.8.3  (abort with ^G)
> 1> {ok,Port} = gen_udp:open(9000, [binary]).
> {ok,#Port<0.576>}
>
> $ lsof -nP -i|grep beam|grep UDP
> beam.smp  10912  max   11u  IPv4 0x089073c4      0t0  UDP *:9000
>
>
>
> Simulate error:
> 2> a=b.
> ** exception error: no match of right hand side value b
>
> All ports are closed.
>
> $ lsof -nP -i|grep beam|grep UDP
> $
>
>
> Now add controlling_process:
>
> 4> {ok,Port} = gen_udp:open(9000, [binary]).
> {ok,#Port<0.587>}
> 5> gen_udp:controlling_process(Port, self()).
> ok
> 6> a=b.
> ** exception error: no match of right hand side value b
>
> Voila: port is not closed
>
> lsof -nP -i|grep beam|grep UDP
> beam.smp  10912  max   11u  IPv4 0x089073c4      0t0  UDP *:9000
>
>
> Where is it? To which process belongs it now and when will it be closed?
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
> *"Have run Make so many times I dunno what's installed anymore"*
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>


-- 
Best Regards,
- Ahmed Omar
http://nl.linkedin.com/in/adiaa
Follow me on twitter
@spawn_think <http://twitter.com/#!/spawn_think>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110427/65704c0d/attachment.htm>


More information about the erlang-questions mailing list