increment failures on timeout (#651)

As of c-ares 1.22.0, server timeouts were erroneously not incrementing server failures meaning the server in use wouldn't rotate.  There was apparently never a test case for this condition.

This PR fixes the bug and adds a test case to ensure it behaves properly.

Fixes Bug: #650 
Fix By: Brad House (@bradh352)
pull/653/head
Brad House 12 months ago committed by GitHub
parent aed78f1665
commit f24d7c9b52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/lib/ares_process.c
  2. 24
      test/ares-test-mock.cc

@ -562,6 +562,7 @@ static void process_timeouts(ares_channel_t *channel, struct timeval *now)
query->timeouts++;
conn = query->conn;
server_increment_failures(conn->server);
ares__requeue_query(query, now);
ares__check_cleanup_conn(channel, conn);

@ -1341,6 +1341,30 @@ TEST_P(NoRotateMultiMockTest, ThirdServer) {
CheckExample();
}
TEST_P(NoRotateMultiMockTest, ServerNoResponseFailover) {
std::vector<byte> nothing;
DNSPacket okrsp;
okrsp.set_response().set_aa()
.add_question(new DNSQuestion("www.example.com", T_A))
.add_answer(new DNSARR("www.example.com", 100, {2,3,4,5}));
ON_CALL(*servers_[0], OnRequest("www.example.com", T_A))
.WillByDefault(SetReplyData(servers_[0].get(), nothing));
ON_CALL(*servers_[1], OnRequest("www.example.com", T_A))
.WillByDefault(SetReplyData(servers_[1].get(), nothing));
EXPECT_CALL(*servers_[2], OnRequest("www.example.com", T_A))
.WillOnce(SetReply(servers_[2].get(), &okrsp));
HostResult result;
ares_gethostbyname(channel_, "www.example.com.", AF_INET, HostCallback, &result);
Process();
EXPECT_TRUE(result.done_);
EXPECT_EQ(2, result.timeouts_);
std::stringstream ss;
ss << result.host_;
EXPECT_EQ("{'www.example.com' aliases=[] addrs=[2.3.4.5]}", ss.str());
}
INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockChannelTest, ::testing::ValuesIn(ares::test::families_modes));
INSTANTIATE_TEST_SUITE_P(AddressFamilies, MockUDPChannelTest, ::testing::ValuesIn(ares::test::families));

Loading…
Cancel
Save