Skip to content

Commit

Permalink
gethostbyaddr: fail with ECANCELLED for ares_cancel()
Browse files Browse the repository at this point in the history
When `ares_cancel()` was invoked, `ares_gethostbyaddr()`
queries would fail with `ENOTFOUND` instead of `ECANCELLED`.

It seems appropriate to treat `ares_cancel()` like `ares_destroy()`,
but I would appreciate review of the correctness of this change.

Ref: nodejs/node#14814

Closes c-ares#138
  • Loading branch information
addaleax authored and DronRathore committed Mar 11, 2020
1 parent 5311871 commit d1b9f98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ares_gethostbyaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static void addr_callback(void *arg, int status, int timeouts,
}
end_aquery(aquery, status, host);
}
else if (status == ARES_EDESTRUCTION)
else if (status == ARES_EDESTRUCTION || status == ARES_ECANCELLED)
end_aquery(aquery, status, NULL);
else
next_lookup(aquery);
Expand Down
12 changes: 12 additions & 0 deletions test/ares-test-mock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,18 @@ TEST_P(MockChannelTest, CancelImmediate) {
EXPECT_EQ(0, result.timeouts_);
}

TEST_P(MockChannelTest, CancelImmediateGetHostByAddr) {
HostResult result;
struct in_addr addr;
addr.s_addr = htonl(0x08080808);

ares_gethostbyaddr(channel_, &addr, sizeof(addr), AF_INET, HostCallback, &result);
ares_cancel(channel_);
EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_ECANCELLED, result.status_);
EXPECT_EQ(0, result.timeouts_);
}

// Relies on retries so is UDP-only
TEST_P(MockUDPChannelTest, CancelLater) {
std::vector<byte> nothing;
Expand Down

0 comments on commit d1b9f98

Please sign in to comment.