c-ares: Fail to resolve after DNS server dies and another server starts

After upgrade from 1.20.1 to 1.22.1 we are noticing failures in test that checks switching from a dead DNS server to an alive one.

The test: 0) Sets the following c-ares options https://github.com/userver-framework/userver/blob/00d7a3ddf31c318a92fde08f19f4d8c5159a7e48/core/src/clients/dns/net_resolver.cpp#L179-L192

  1. Calls ares_set_servers_ports_csv with [::1]:3000 and [::1]:3001
  2. Start DNS server at [::1]:3000 (DNS server at [::1]:3001 is not started!)
  3. Resolve some hosts via c-ares
  4. Kill DNS server at [::1]:3000 and start a new DNS server at [::1]:3001
  5. Resolve a host
  6. Kill DNS server at [::1]:3001 and start a DNS server at [::1]:3000
  7. Attempt to resolve a host times out (timeout=15 seconds). However the DNS server at [::1]:3000 was requested by c-ares and the DNS server successfully responded in the same second it was requested

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (10 by maintainers)

Most upvoted comments

closing since this appears to work as expected

FYI, we have a release prepped for c-ares 1.24.0 that we’d like to get out the door. I’d like to hold the release up to a couple of days to figure this issue out, however. So as much information you can provide would be appreciated so we can get to the bottom of this.

I’ve confirmed what I said is accurate, the mock server doesn’t send anything at all, it acts like a lost packet which is normal for UDP since its connectionless: https://github.com/c-ares/c-ares/blob/main/test/ares-test.cc#L422

You can see this too when running ./bin/arestest -v --gtest_filter=*ServerNoResponseFailover*, note the missing “sending reply” for the requests that are dropped:

[ RUN      ] TransportModes/NoRotateMultiMockTest.ServerNoResponseFailover/0
Configured IPv4 mock server with TCP socket 3 on port 50507 and UDP socket 4 on port 60081
Configured IPv4 mock server with TCP socket 5 on port 50508 and UDP socket 6 on port 57182
Configured IPv4 mock server with TCP socket 7 on port 50509 and UDP socket 8 on port 56648
Configured library with servers:127.0.0.1:60081,127.0.0.1:57182,127.0.0.1:56648
received UDP request REQ QRY RD  Q:{'www.example.com' IN A} ADD:{'' MAXUDP=1280 OPT RCODE2=0 } on port 60081
ProcessRequest(56206, 'www.example.com', A)
sending reply RSP QRY AA NOERROR Q:{'www.example.com' IN A} A:{'www.example.com' IN A TTL=100 2.3.4.5} on port 60081
HostCallback({ARES_SUCCESS {'www.example.com' aliases=[] addrs=[2.3.4.5]}})
received UDP request REQ QRY RD  Q:{'www.example.com' IN A} ADD:{'' MAXUDP=1280 OPT RCODE2=0 } on port 60081
ProcessRequest(52222, 'www.example.com', A)
received UDP request REQ QRY RD  Q:{'www.example.com' IN A} ADD:{'' MAXUDP=1280 OPT RCODE2=0 } on port 57182
ProcessRequest(52222, 'www.example.com', A)
received UDP request REQ QRY RD  Q:{'www.example.com' IN A} ADD:{'' MAXUDP=1280 OPT RCODE2=0 } on port 56648
ProcessRequest(52222, 'www.example.com', A)
sending reply RSP QRY AA NOERROR Q:{'www.example.com' IN A} A:{'www.example.com' IN A TTL=100 2.3.4.5} on port 56648
HostCallback({ARES_SUCCESS {'www.example.com' aliases=[] addrs=[2.3.4.5]}})
received UDP request REQ QRY RD  Q:{'www.example.com' IN A} ADD:{'' MAXUDP=1280 OPT RCODE2=0 } on port 56648
ProcessRequest(19226, 'www.example.com', A)
sending reply RSP QRY AA NOERROR Q:{'www.example.com' IN A} A:{'www.example.com' IN A TTL=100 2.3.4.5} on port 56648
HostCallback({ARES_SUCCESS {'www.example.com' aliases=[] addrs=[2.3.4.5]}})
received UDP request REQ QRY RD  Q:{'www.example.com' IN A} ADD:{'' MAXUDP=1280 OPT RCODE2=0 } on port 56648
ProcessRequest(32658, 'www.example.com', A)
received UDP request REQ QRY RD  Q:{'www.example.com' IN A} ADD:{'' MAXUDP=1280 OPT RCODE2=0 } on port 60081
ProcessRequest(32658, 'www.example.com', A)
sending reply RSP QRY AA NOERROR Q:{'www.example.com' IN A} A:{'www.example.com' IN A TTL=100 2.3.4.5} on port 60081
HostCallback({ARES_SUCCESS {'www.example.com' aliases=[] addrs=[2.3.4.5]}})

Have you tried the patch from #651 ?