[erlang-questions] race condition on BEAM startup before DNS queries function

Kenneth Lakin kennethlakin@REDACTED
Sat Nov 21 03:29:18 CET 2015


On 11/20/2015 05:20 AM, Dave Cottlehuber wrote:
> It seems there is some module or application that is required as a
> dependency for e.g. DNS queries to work reliably, when the BEAM starts
> up [1].
> 
> If the delay is set to 5 seconds, this lookup works reliably, if it is
> 0, then it fails reliably:

It *feels* like the following logic in res_update/5 (in inet_db.erl) is
the culprit:

res_update(Tag, TagTm, TagInfo, TagSetTm, SetFun) ->
    case db_get(TagTm) of
      undefined -> ok;
      TM ->
        case times() of
          Now when Now >= TM + ?RES_FILE_UPDATE_TM ->
            %<snip>
          _ ->
            ok
        end
      end.

RES_FILE_UPDATE_TM is defined as 5. The comment next to it declares that
its unit is seconds. inet_db:times/0 is

times() ->
  erlang:convert_time_unit(erlang:monotonic_time() -
  erlang:system_info(start_time),native,seconds).

inet_db:times/0 appears to return the number of seconds the system has
been up.

Some tracing and prints reveals that the nameservers list passed in to
the call to inet_res:do_query is *not* populated until the system has
been up and running for ~five seconds (that is, until inet_db:times/0
returns 5).

The call immediately prior to the times/0 call is

inet_db:db_get(res_resolv_conf_tm)

This ends up being a lookup into the inet_db ETS table. I don't know
what the value of res_resolv_conf_tm is, but maybe it *might* be
possible to set it to

-?RES_FILE_UPDATE_TM

so that DNS lookups will load the nameservers defined in resolv.conf
when the system initially starts up, rather than having to wait for five
seconds?

But maybe I'm wrong about all of that.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151120/ef12d8b3/attachment.bin>


More information about the erlang-questions mailing list