[erlang-questions] Erlang 19.3 crashes when getting sockname of stdin

Danil Zagoskin z@REDACTED
Mon Oct 16 15:18:06 CEST 2017


Hi!
Before calling inet:sockname on a port first make sure it's inet_tcp or
inet_udp.
For example,
[{inet:sockname(P), erlang:port_info(P, connected)} || P <- erlang:ports(),
erlang:port_get_data(P) == inet_tcp].

You also can filter by name from erlang:port_info/1:
[{inet:sockname(P), erlang:port_info(P, connected)} || P <- erlang:ports(),
erlang:port_info(P, name) == {name,"tcp_inet"}].


On Mon, Oct 16, 2017 at 3:14 PM, Attila Rajmund Nohl <
attila.r.nohl@REDACTED> wrote:

> Hello!
>
> I have a oneliner that prints out which erlang process is listening on
> a given TCP port. Recently I upgraded from Debian 8.9 to Debian 9.2
> and on Erlang/OTP 19.3.1 this oneliner no longer works. The minimal
> example to reproduce:
>
> Erlang/OTP 19 [erts-8.3.1] [source] [64-bit] [smp:2:2]
> [async-threads:10] [hipe] [kernel-poll:false]
>
> Eshell V8.3.1  (abort with ^G)
> 1> inet:sockname(self()).
> ** exception error: no function clause matching
> prim_inet:sockname(<0.58.0>)
> 2> inet:sockname(hd(erlang:ports())).
> Failed to write to erl_child_setup: 9
>
> Crash dump is being written to: erl_crash.dump...done
>
> The (relevant?) part of the crash dump:
>
> Current Process: <0.60.0>
> Current Process State: Running
> Current Process Internal State: ACT_PRIO_NORMAL | USR_PRIO_NORMAL |
> PRQ_PRIO_NORMAL | ACTIVE | RUNNING | ON_HEAP_MSGQ
> Current Process Program counter: 0x00007f695af4b1d0 (unknown function)
> Current Process CP: 0x0000000000000000 (invalid)
> Current Process Limited Stack Trace:
> 0x00007f6958e16048:SReturn addr 0x5C473830 (prim_inet:ctl_cmd/3 + 64)
> 0x00007f6958e16070:SReturn addr 0x5C45F3F8 (prim_inet:sockname/1 + 96)
> 0x00007f6958e16080:SReturn addr 0x5C291510 (erl_eval:do_apply/6 + 408)
> 0x00007f6958e16088:SReturn addr 0x580DF1B0 (shell:exprs/7 + 632)
> 0x00007f6958e160a0:SReturn addr 0x580DE8D0 (shell:eval_exprs/7 + 128)
> 0x00007f6958e160f8:SReturn addr 0x580DE4C8 (shell:eval_loop/3 + 576)
> 0x00007f6958e16130:SReturn addr 0x943E78 (<terminate process normally>)
>
> Erlang is built from source using kerl. This used to work on Debian
> 8.9 (as far as I remember, but I may be wrong here) and this also
> works (at least doesn't crash the VM) on Erlang 18.3:
>
> 3> inet:sockname(hd(erlang:ports())).
> ** exception error: no try clause matching []
>      in function  prim_inet:ctl_cmd/3
>      in call from prim_inet:sockname/1
>
> Sometimes my terminal hangs when I reproduce this bug. I just checked
> and I got similar crash on OS X too with Erlang/OTP 19.3.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>



-- 
Danil Zagoskin | z@REDACTED
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20171016/dbe1a149/attachment.htm>


More information about the erlang-questions mailing list