dnsimple / erldns

DNS server, in Erlang.
MIT License
402 stars 98 forks source link

mnesia broken #102

Closed nisbus closed 4 years ago

nisbus commented 4 years ago

Mnesia implementation is broken for two methods (that I've tested).
erldns_zone_cache:zone_names_and_versions()
erldns_zone_cache:get_zone_records()

Steps to reproduce:

git clone git@github.com:dnsimple/erldns.git
cp erldns.config.example erldns.config

Add to erldns.config:

{erldns, 
    {storage, [
                {type, erldns_storage_mnesia},
                {dir, "."}
            ]
    },
    ....Default config
},
{mnesia, [{dir, "."}]}

Run:

rebar3 shell

Query:

dig @127.0.0.1 -p 8053 example.com

 <<>> DiG 9.16.1-Ubuntu <<>> @127.0.0.1 -p 8053 example.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 26391
;; flags: qr aa rd; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 3993fc8d0b301228 (echoed)
;; QUESTION SECTION:
;example.com.           IN  A

;; AUTHORITY SECTION:
example.com.        300 IN  SOA ns1.example.com. admin.example.com. 2013022001 86400 7200 604800 300

;; Query time: 3 msec
;; SERVER: 127.0.0.1#8053(127.0.0.1)
;; WHEN: Tue Jun 09 11:19:42 CEST 2020
;; MSG SIZE  rcvd: 98

See issue in shell

zone_names_and_versions

1> erldns_zone_cache:zone_names_and_versions().
** exception exit: {aborted,function_clause}
     in function  mnesia:wrap_trans/6 (mnesia.erl, line 497)

How to fix

Edit erldns_zone_cache.erl

From:

zone_names_and_versions() ->
  erldns_storage:foldl(fun({_, Zone}, NamesAndShas) -> NamesAndShas ++ [{Zone#zone.name, Zone#zone.version}] end, [], zones).

To:

zone_names_and_versions() ->
  erldns_storage:foldl(fun(Zone, NamesAndShas) -> NamesAndShas ++ [{Zone#zone.name, Zone#zone.version}] end, [], zones).
rebar3 shell
1> erldns_zone_cache:zone_names_and_versions().
[{<<"example.com">>,[]}]

This breaks the JSON version though so not ideal.

get_zone_records:

4> erldns_zone_cache:get_zone_records(<<"example.com">>).     
** exception exit: {aborted,{bad_type,[{{{<<"example.com">>,'_'},'$1'},
                                        [],
                                        ['$$']}]}}
     in function  mnesia:wrap_trans/6 (mnesia.erl, line 497)
     in call from erldns_zone_cache:get_zone_records/1 (/home/nisbus/code/osource/erldns_clean/src/erldns_zone_cache.erl, line 153)

Not sure how to fix this one

Thanks

m0rcq commented 4 years ago

Hello @nisbus - thank you for reporting this!

This has been fixed and PR is in the pipeline, I will let you know once it has been merged.

m0rcq commented 4 years ago

Closing this issue: https://github.com/dnsimple/erldns/pull/103 addresses these bugs, merged to master now.