network: fixed cleanup order in UDP timeout handler
network: added a time delta to the UDP timeout to keep it from
ticking after the upstream timeout handler.
@@ -602,12 +602,12 @@ static void flb_net_getaddrinfo_timeout_handler(struct flb_config *config, void
*(lookup_context->udp_timeout_detected) = 1;
- ares_cancel(lookup_context->ares_channel);
-
if (lookup_context->ares_socket_created) {
mk_event_del(lookup_context->event_loop, &lookup_context->response_event);
}
+ ares_cancel(lookup_context->ares_channel);
+
flb_coro_resume(lookup_context->coroutine);
flb_net_dns_lookup_context_destroy(lookup_context);
@@ -771,6 +771,15 @@ int flb_net_getaddrinfo(const char *node, const char *service, struct addrinfo *
*/
timeout *= 1000;
+ /* We need to ensure that our timer won't overlap with the upstream timeout handler.
+ */
+ if (timeout > 500) {
+ timeout -= 500;
+ }
+ else {
+ timeout /= 2;
+ }
+
ares_hints.ai_flags = hints->ai_flags;
ares_hints.ai_family = hints->ai_family;
ares_hints.ai_socktype = hints->ai_socktype;
