<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>Hi,</p>
<p>using this <a
href="https://github.com/jeremyong/websocket_client">Erlang
websocket library</a> I've come across an unpleasant situation:
should the network interface be initially down upon attempting to
establish a websocket connection with some server, it will keep
indefinitely on failing with <tt>{error, nxdomain}</tt>, even if
the network interface eventually comes up.</p>
<p>This is the line that fails (full source <a
href="https://github.com/jeremyong/websocket_client/blob/master/src/websocket_client.erl">here</a>):</p>
<p><tt>gen_tcp:connect(Host, Port, [binary,{active, false},{packet,
0}]</tt><tt>, 6000)</tt><br>
</p>
<p>When executed with my wireless interface disabled (no other
connection available):</p>
<p><tt>iex(10)> :gen_tcp.connect(myHost, somePort, [:binary,
{:active, false}, {:packet, 0}], 6000)</tt><tt><br>
</tt><tt>{:error, :nxdomain}</tt></p>
<p>Please note that</p>
<p><tt>iex(11)> :inet_res.gethostbyname myHost </tt><tt><br>
</tt><tt>{:error, :nxdomain}</tt></p>
<p>and</p>
<p><tt>iex(12)> :inet.getifaddrs()</tt><tt><br>
</tt><tt>{:ok,</tt><tt><br>
</tt><tt> [{'lo',</tt><tt><br>
</tt><tt> [flags: [:up, :loopback, :running], hwaddr: [0, 0, 0,
0, 0, 0],</tt><tt><br>
</tt><tt> addr: {127, 0, 0, 1}, netmask: {255, 0, 0, 0},</tt><tt><br>
</tt><tt> addr: {0, 0, 0, 0, 0, 0, 0, 1},</tt><tt><br>
</tt><tt> netmask: {65535, 65535, 65535, 65535, 65535, 65535,
65535, 65535}]},</tt><tt><br>
</tt><tt> {'enp4s0f2',</tt><tt><br>
</tt><tt> [flags: [:up, :broadcast, :running, :multicast],</tt><tt><br>
</tt><tt> hwaddr: [0, 144, 245, 236, 118, 237]]},</tt><tt><br>
</tt><tt> {'wlp3s0',</tt><tt><br>
</tt><tt> [flags: [:broadcast, :multicast], hwaddr: [238, 247,
218, 133, 87, 184]]},</tt></p>
<p><tt> ...</tt><br>
</p>
<p>being wlp3s0 my wireless network interface; now I turn on my
wireless card again, so that</p>
<p><tt>iex(13)> :inet.getifaddrs()</tt><tt><br>
</tt><tt>{:ok,</tt><tt><br>
</tt><tt> [{'lo',</tt><tt><br>
</tt><tt> [flags: [:up, :loopback, :running], hwaddr: [0, 0, 0,
0, 0, 0],</tt><tt><br>
</tt><tt> addr: {127, 0, 0, 1}, netmask: {255, 0, 0, 0},</tt><tt><br>
</tt><tt> addr: {0, 0, 0, 0, 0, 0, 0, 1},</tt><tt><br>
</tt><tt> netmask: {65535, 65535, 65535, 65535, 65535, 65535,
65535, 65535}]},</tt><tt><br>
</tt><tt> {'enp4s0f2',</tt><tt><br>
</tt><tt> [flags: [:up, :broadcast, :running, :multicast],</tt><tt><br>
</tt><tt> hwaddr: [0, 144, 245, 236, 118, 237]]},</tt><tt><br>
</tt><tt> {'wlp3s0',</tt><tt><br>
</tt><tt> [flags: [:up, :broadcast, :running, :multicast],</tt><tt><br>
</tt><tt> hwaddr: [96, 108, 102, 213, 237, 125], addr: {192,
168, 1, 36},</tt><tt><br>
</tt><tt> netmask: {255, 255, 255, 0}, broadaddr: {192, 168, 1,
255},</tt><tt><br>
</tt><tt> addr: {65152, 0, 0, 0, 44736, 36, 25537, 54250},</tt><tt><br>
</tt><tt> netmask: {65535, 65535, 65535, 65535, 0, 0, 0, 0}]},</tt></p>
<p><tt> ...</tt><br>
</p>
<p>and</p>
<p><tt>iex(14)> :inet_res.gethostbyname myHost </tt><tt><br>
</tt><tt>{:ok, {:hostent, '[obfuscated]', [], :inet, 4, [{94, 23,
48, 116}]}}</tt><br>
</p>
<p>but any attempt to gen_tcp:connect again (from a newly launched
proc) will keep on yielding a nxdomain error.</p>
<p>I'm running this on a Fedora 25 box with Erlang 19 and Elixir
1.4.2. I use Erlang's out-of-the-box inet configuration:</p>
<p><tt>iex(4)> :inet.get_rc()</tt><tt><br>
</tt><tt>[domain: 'localdomain', search: ['localdomain'],</tt><tt><br>
</tt><tt> resolv_conf: '/etc/resolv.conf', hosts_file:
'/etc/hosts', lookup: [:native]]</tt><br>
<br>
</p>
<p>Any clue as to what is happening and how could it be fixed? Is it
a configuration problem or rather am I or the Jeremyoung library
using gen_tcp improperly?</p>
<p>Kind regards<br>
</p>
<br>
<div class="moz-signature"><br>
</div>
</body>
</html>