[erlang-bugs] Bug in the resolver?

Ahmed Omar spawn.think@REDACTED
Wed Apr 13 11:08:09 CEST 2011


If you agree with it, i can submit a proper patch

On Wed, Apr 13, 2011 at 11:06 AM, Ahmed Omar <spawn.think@REDACTED> wrote:

> Indeed you are correct. I wrote it in a different way, removed the
> undefined and avoided subtraction if Timeout is 0
> diff --git a/lib/kernel/src/inet_res.erl b/lib/kernel/src/inet_res.erl
> index de0f23b..0ba5969 100644
> --- a/lib/kernel/src/inet_res.erl
> +++ b/lib/kernel/src/inet_res.erl
> @@ -547,15 +547,16 @@ udp_recv(#sock{inet=I}, {A,B,C,D}=IP, Port, Timeout)
>      do_udp_recv(fun(T) -> gen_udp:recv(I, 0, T) end, IP, Port, Timeout).
>
>  do_udp_recv(Recv, IP, Port, Timeout) ->
> -    do_udp_recv(Recv, IP, Port, Timeout,
> -               if Timeout =/= 0 -> erlang:now(); true -> undefined end).
> +    do_udp_recv(Recv, IP, Port, Timeout, erlang:now()).
>
>  do_udp_recv(Recv, IP, Port, Timeout, Then) ->
>      case Recv(Timeout) of
> +       {ok,{IP,Port,Answer}} when Timeout =:= 0->
> +           {ok, Answer, Timeout};
>         {ok,{IP,Port,Answer}} ->
>             {ok,Answer,erlang:max(0, Timeout - now_ms(erlang:now(),
> Then))};
> -       {ok,_} when Timeout =:= 0 ->
> -           {error,timeout};
> +        {ok,_} when Timeout =:= 0 ->
> +            {error,timeout};
>         {ok,_} ->
>             Now = erlang:now(),
>             T = erlang:max(0, Timeout - now_ms(Now, Then)),
>
>
> On Wed, Apr 13, 2011 at 10:43 AM, Raimo Niskanen <
> raimo+erlang-bugs@REDACTED> wrote:
>
>> On Tue, Apr 12, 2011 at 01:56:26PM +0200, Ahmed Omar wrote:
>> > Then going back to my original message, the order of case clauses
>> doesn't
>> > sound right
>> > {ok,{IP,Port,Answer}} ->
>> >     {ok,Answer,erlang:max(0, Timeout - now_ms(erlang:now(), Then))};
>> > {ok,_} when Timeout =:= 0 ->
>> >         {error,timeout};
>> >
>> >
>> > Cause even when the timeout is 0 now, now_ms/2 will be called with Then
>> =
>> > undefined
>>
>> I will dig into this in a few days, after my current tasks, and will
>> post a diff when the yet unwritten testcases start working...
>>
>> >
>> > On Tue, Apr 12, 2011 at 1:51 PM, Raimo Niskanen <
>> > raimo+erlang-bugs@REDACTED> wrote:
>> >
>> > > On Tue, Apr 12, 2011 at 01:35:33PM +0200, Raimo Niskanen wrote:
>> > > > On Tue, Apr 12, 2011 at 01:08:24PM +0200, Ahmed Omar wrote:
>> > > > > Hmmm, the crash doesn't look to be in subtraction (otherwise it
>> would
>> > > have
>> > > > > been badarg?),  it's a crash because of a function clause in
>> now_ms
>> > > (because
>> > > > > undefined won't match)
>> > > > > (and undefined looks to be generated only when timeout is 0 )
>> > > >
>> > > > Well, I ment _conceptually_ subtract since now_ms/2 is supposed to
>> > > > return the number of elapsed microseconds i.e subtract
>> > >
>> > > Milliseconds. Sorry. That should be milliseconds.
>> > >
>> > > > its now() arguments, and now got 'undefined' instead
>> > > > of {MegaSec,Sec,MicroSec) as second argumnent.
>> > > >
>> > > > 'undefined' must be a leftover from an unfinished implementation
>> > > > of either the case when you have timed out or when the
>> > > > timeout is 'infinity'. Nevertheless it is incorrect.
>> > > >
>> > > > The Timeout variable is how long time still remains to wait of the
>> > > > initial user interface timeout.
>> > > >
>> > > > >
>> > > > > Maybe I'm missing something or my coffee doesn't work :)
>> > > > >
>> > > : :
>> > > > > Follow me on twitter
>> > > > > @spawn_think <http://twitter.com/#!/spawn_think>
>> > > >
>> > > > --
>> > > >
>> > > > / Raimo Niskanen, Erlang/OTP, Ericsson AB
>> > > > _______________________________________________
>> > > > erlang-bugs mailing list
>> > > > erlang-bugs@REDACTED
>> > > > http://erlang.org/mailman/listinfo/erlang-bugs
>> > >
>> > > --
>> > >
>> > > / Raimo Niskanen, Erlang/OTP, Ericsson AB
>> > > _______________________________________________
>> > > erlang-bugs mailing list
>> > > erlang-bugs@REDACTED
>> > > http://erlang.org/mailman/listinfo/erlang-bugs
>> > >
>> >
>> >
>> >
>> > --
>> > Best Regards,
>> > - Ahmed Omar
>> > http://nl.linkedin.com/in/adiaa
>> > Follow me on twitter
>> > @spawn_think <http://twitter.com/#!/spawn_think>
>>
>> --
>>
>> / Raimo Niskanen, Erlang/OTP, Ericsson AB
>> _______________________________________________
>> erlang-bugs mailing list
>> erlang-bugs@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-bugs
>>
>
>
>
> --
> Best Regards,
> - Ahmed Omar
> http://nl.linkedin.com/in/adiaa
> Follow me on twitter
> @spawn_think <http://twitter.com/#!/spawn_think>
>
>


-- 
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-bugs/attachments/20110413/73a13473/attachment.htm>


More information about the erlang-bugs mailing list