Skip to content

Commit e8a8637

Browse files
committed
Make gethostbyaddr fail with ECANCELLED for ares_cancel()
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
1 parent 33bf5ba commit e8a8637

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

ares_gethostbyaddr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static void addr_callback(void *arg, int status, int timeouts,
157157
}
158158
end_aquery(aquery, status, host);
159159
}
160-
else if (status == ARES_EDESTRUCTION)
160+
else if (status == ARES_EDESTRUCTION || status == ARES_ECANCELLED)
161161
end_aquery(aquery, status, NULL);
162162
else
163163
next_lookup(aquery);

test/ares-test-mock.cc

+12
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,18 @@ TEST_P(MockChannelTest, CancelImmediate) {
883883
EXPECT_EQ(0, result.timeouts_);
884884
}
885885

886+
TEST_P(MockChannelTest, CancelImmediateGetHostByAddr) {
887+
HostResult result;
888+
struct in_addr addr;
889+
addr.s_addr = htonl(0x08080808);
890+
891+
ares_gethostbyaddr(channel_, &addr, sizeof(addr), AF_INET, HostCallback, &result);
892+
ares_cancel(channel_);
893+
EXPECT_TRUE(result.done_);
894+
EXPECT_EQ(ARES_ECANCELLED, result.status_);
895+
EXPECT_EQ(0, result.timeouts_);
896+
}
897+
886898
// Relies on retries so is UDP-only
887899
TEST_P(MockUDPChannelTest, CancelLater) {
888900
std::vector<byte> nothing;

0 commit comments

Comments
 (0)