[erlang-questions] inet_res:getbyname/2 and udp:connect/3

Tony Rogvall <>
Wed Jun 16 14:35:24 CEST 2010


On 16 jun 2010, at 08.07, Per Hedeland wrote:

> 
>> Try an other interface where there is a host ...
> 
> Haven't done that, maybe I will (right now I happen to be on a network
> where other hosts don't have the courtesy to send ICMP unreachables:-).
> I noticed something else interesting though - in passive mode:
> 
> 9> gen_udp:send(U, <<1,2,3>>).        
> ok
> 10> gen_udp:send(U, <<1,2,3>>).        
> {error,econnrefused}
> 11> gen_udp:send(U, <<1,2,3>>).        
> ok
> 12> gen_udp:send(U, <<1,2,3>>).
> {error,econnrefused}
> 13> gen_udp:send(U, <<1,2,3>>).
> ok
> 14> gen_udp:send(U, <<1,2,3>>).        
> {error,econnrefused}
> 
> I.e. the error is detected, but only on a subsequent send() (which
> doesn't actually send anything).
> 
Cool! 
send is failing on subsequent send, but recv is not ???? This is strange times.
Do you think this behavior is documented anywhere?
A small C program may clear this issue for us ?

/Tony

A small comment intended for the list readers that do understand what we are talking about.

When running the inet_res:resolve function (and friends) it will never return {error,econnrefused}
But the result {error,timeout} even before the timeout value. This may be a bug or not, for now it is "historical reasons" and
"convenient". The reasons is that one or several name severs may get econnrefused while others may timeout.
To get the {error, econnrefused} speed things up when trying servers where DNS servers may have crashed.
But in the general case, server may be down/burned, routers is down/corrupt, this will not help since no one will send
the ICMP reply message on the network.

Example:

inet_res:resolve("www.rogvall.se", in, a, [{nameservers,[{{127,0,0,1},53}]},verbose], 5000).
Query: {msg,[{header,{header,[{id,7},
                              {qr,0},
                              {opcode,'query'},
                              {aa,0},
                              {tc,0},
                              {rd,true},
                              {ra,0},
                              {pr,0},
                              {rcode,0}]}},
             {qdlist,[{dns_query,[{domain,"www.rogvall.se"},
                                  {type,a},
                                  {class,in}]}]},
             {anlist,[]},
             {nslist,[]},
             {arlist,[]}]}
Try UDP server : {127,0,0,1}:53 (timeout=666)
UDP server error: {error,econnrefused}
{error,timeout}

Trying a host that do not exist:

inet_res:resolve("www.rogvall.se", in, a, [{nameservers,[{{127,0,0,2},53}]},verbose], 5000).
Query: {msg,[{header,{header,[{id,8},
                              {qr,0},
                              {opcode,'query'},
                              {aa,0},
                              {tc,0},
                              {rd,true},
                              {ra,0},
                              {pr,0},
                              {rcode,0}]}},
             {qdlist,[{dns_query,[{domain,"www.rogvall.se"},
                                  {type,a},
                                  {class,in}]}]},
             {anlist,[]},
             {nslist,[]},
             {arlist,[]}]}
Try UDP server : {127,0,0,2}:53 (timeout=666)
UDP server error: {error,timeout}
Try UDP server : {127,0,0,2}:53 (timeout=1333)
UDP server error: {error,timeout}
Try UDP server : {127,0,0,2}:53 (timeout=2666)
UDP server error: {error,timeout}
{error,timeout}





/Tony



More information about the erlang-questions mailing list