network: fixed a local resolution corner case
@@ -727,16 +727,7 @@ static ares_socket_t flb_dns_ares_socket(int af, int type, int protocol, void *u
event_mask = MK_EVENT_READ;
- /*
- * c-ares doesn't use a macro for the socket type so :
- * 1 means it's a TCP socket
- * 2 means it's a UDP socket
- *
- * For TCP sockets we want to monitor for write events because we need to call
- * ares_process_fd in order to issue the query unlike UDP sockets which automatically
- * send the query after creating the socket.
- */
- if (FLB_ARES_SOCKET_TYPE_TCP == type) {
+ if (SOCK_STREAM == type) {
event_mask |= MK_EVENT_WRITE;
}
@@ -929,7 +920,7 @@ int flb_net_getaddrinfo(const char *node, const char *service, struct addrinfo *
/* We need to ensure that our timer won't overlap with the upstream timeout handler.
*/
- if (timeout > 1000) {
+ if (timeout > 3000) {
timeout -= 1000;
}
else {
@@ -944,8 +935,9 @@ int flb_net_getaddrinfo(const char *node, const char *service, struct addrinfo *
ares_getaddrinfo(lookup_context->ares_channel, node, service, &ares_hints,
flb_net_getaddrinfo_callback, lookup_context);
+ if (!lookup_context->finished) {
if (lookup_context->ares_socket_created) {
- if (lookup_context->ares_socket_type == FLB_ARES_SOCKET_TYPE_UDP) {
+ if (lookup_context->ares_socket_type == SOCK_DGRAM) {
/* If the socket type created by c-ares is UDP then we need to create our
* own timeout mechanism before yielding and cancel it if things go as
* expected.
@@ -980,6 +972,10 @@ int flb_net_getaddrinfo(const char *node, const char *service, struct addrinfo *
flb_coro_yield(coroutine, FLB_FALSE);
}
}
+ else {
+ /* Do we want to do anything special for this condition? */
+ }
+ }
else {
lookup_context->coroutine = NULL;
@@ -1097,6 +1093,21 @@ flb_sockfd_t flb_net_tcp_connect(const char *host, unsigned long port,
return -1;
}
+ if (u_conn->net_error > 0) {
+ if (u_conn->net_error == ETIMEDOUT) {
+ flb_warn("[net] timeout detected between DNS lookup and connection attempt");
+ }
+
+ if (is_async) {
+ flb_net_free_translated_addrinfo(res);
+ }
+ else {
+ freeaddrinfo(res);
+ }
+
+ return -1;
+ }
+
/*
* Try to connect: on this iteration we try to connect to the first
* available address.
