Doubt for unbound process flow when run command "dig @localhost . ns"

all,
when I run command “dig @localhost . ns”,I used tcpdump to capture the DNS packets,I found that unbound query root DNS server twice, why?

Hi Jianjun,

all, when I run command "dig @localhost . ns",I used tcpdump to
capture the DNS packets,I found that unbound query root DNS server
twice, why?

The first is the root prime query, the second is the query to fetch
your answer. The reason it does it twice is that the first query is
run while the state machine in unbound does not perform further
recursions, and the second has the state machine set to store the
answer for the user. So, with the first it fetches the addresses of
the root servers and the second asks one of those root servers for the
answer you wanted. Realistically, the answer is stored in cache and
the second query is not necessary, but there is no code there that
checks the cache for contents; the cache-check code is in a different
position in the implementation. I do not think that this query needs
to have special-case code added to avoid the second query.

Best regards,
   Wouter