fluent-bit icon indicating copy to clipboard operation
fluent-bit copied to clipboard

net.dns.mode TCP: a DNS lookup that times out leaves the output task hanging forever, logged as "connection #-1 to tcp://unavailable:0"

Open fjvbn2003 opened this issue 1 month ago • 1 comments

Bug Report

Describe the bug

With net.dns.mode TCP (the setting used in the example on the Networking page), if the DNS server does not answer, the flush task that is resolving the output host never finishes. net.connect_timeout fires and logs an error, but the task is not failed or retried. Each new chunk adds another task that also hangs, until shutdown.

The only log line is:

[error] [upstream] connection #-1 to tcp://unavailable:0 timed out after 3 seconds (connection timeout)

It doesn't name the output host or port, and doesn't say that the connection was still waiting for DNS.

With the default UDP mode and the same unreachable DNS server, the lookup times out (getaddrinfo(...): Timeout while contacting DNS servers) and the chunk is retried as expected.

To Reproduce

Fluent Bit 5.1.1 (cr.fluentbit.io/fluent/fluent-bit:5.1.1) as a Kubernetes pod whose only nameserver is an unreachable TEST-NET address, so a TCP connection to the DNS server never completes:

dnsPolicy: None
dnsConfig:
  nameservers: ["192.0.2.1"]
( echo '{"msg":1}'; sleep 20; echo '{"msg":2}'; sleep 40 ) | \
/fluent-bit/bin/fluent-bit -i stdin -o opensearch \
  -p host=logs-repro.example.com -p port=9200 -p suppress_type_name=on \
  -p net.connect_timeout=3 -p net.dns.mode=TCP -p retry_limit=1 -f 1

Output (unchanged lines removed):

[2026/10/16 17:18:52.577] [error] [upstream] connection #-1 to tcp://unavailable:0 timed out after 3 seconds (connection timeout)
[2026/10/16 17:19:10.577] [error] [upstream] connection #-1 to tcp://unavailable:0 timed out after 3 seconds (connection timeout)
[2026/10/16 17:19:46.695] [ warn] [input:stdin:stdin.0] end of file (stdin closed by remote end)
[2026/10/16 17:19:46.695] [ warn] [engine] service will shutdown in max 5 seconds
[2026/10/16 17:19:47.077] [ info] [task] stdin/stdin.0 has 2 pending task(s):
...
[2026/10/16 17:19:51.077] [ info] [engine] service has stopped (2 pending tasks)

There is no failed to flush chunk or cannot be retried line for either chunk. With one record and stdin kept open for 60 s, the task was still pending 55 s after the timeout. Setting options: [{name: use-vc}] in the pod's resolv.conf instead of net.dns.mode=TCP gives the same result.

The same command without net.dns.mode=TCP (UDP):

[ warn] [net] getaddrinfo(host='logs-repro.example.com', err=12): Timeout while contacting DNS servers
[ warn] [engine] failed to flush chunk '1-1792170755.183740045.flb', retry in 10 seconds: task_id=0, input=stdin.0 > output=opensearch.0 (out_id=0)
[ warn] [net] getaddrinfo(host='logs-repro.example.com', err=12): Timeout while contacting DNS servers
[error] [engine] chunk '1-1792170755.183740045.flb' cannot be retried: task_id=0, input=stdin.0 > output=opensearch.0

Expected behavior

  • A DNS lookup over TCP gives up after the connect timeout, like UDP does, and the chunk is retried or dropped according to retry_limit.
  • The timeout message names the configured upstream, for example connection to logs-repro.example.com:9200 timed out after 3 seconds while resolving the host name.

Where it seems to come from (reading master at 4dcadc0fea17860ff8d608fe816b869a0ef48999)

  • flb_net_getaddrinfo() in src/flb_network.c creates its own timeout timer (flb_net_getaddrinfo_timeout_handler, which cancels the c-ares query and wakes the coroutine) only when lookup_context->ares_socket_type == SOCK_DGRAM (line 1219). For a TCP socket it yields with no timer (line 1251), so if the TCP connection to the DNS server never completes, nothing resumes the coroutine.
  • The upstream timeout sweep in flb_upstream_conn_timeouts() (src/flb_upstream.c, line 1086) then marks the connection as timed out. The connection has no socket yet (fd == -1) and no peer address, so flb_connection_get_remote_address() returns FLB_NETWORK_ADDRESS_UNAVAILABLE with port 0. As far as I can tell the connection's own event is not registered yet at that point, so the sweep takes the prepare_destroy_conn() branch, and nothing there wakes the coroutine that is waiting on DNS.
  • Other upstream messages in the same file print u->tcp_host and u->tcp_port (for example connection #%i failed to %s:%i), which would name the output here.

A possible fix is to arm the same timer for TCP lookups, and to use u->tcp_host:u->tcp_port in the timeout message when the connection has no socket yet. I have not built Fluent Bit with such a change.

The misleading message also appears with UDP DNS under load. In our cluster (5.1.1 DaemonSet, opensearch output, default net.connect_timeout), during a DNS outage one pod logged 15 connection #-1 to tcp://unavailable:0 timed out after 10 seconds lines next to getaddrinfo(host='...', err=12): Timeout while contacting DNS servers. The same line is quoted in #7105.

Your Environment

  • Version used: 5.1.1 (container image); code paths unchanged on master at the commit above
  • Configuration: command line above; net.dns.mode TCP, net.connect_timeout 3
  • Environment name and version: Kubernetes v1.34.10, containerd, pod with dnsPolicy: None
  • Operating System and version: Ubuntu 26.04, kernel 7.0
  • Filters and plugins: stdin input, opensearch output (any output that uses an upstream should behave the same; not tested)

Additional context

We hit the misleading message during a DNS outage. While reproducing it we found that, with TCP DNS, the task never comes back. In a DaemonSet that would mean chunks stay stuck in memory until the pod restarts.

This issue was drafted with AI assistance and reviewed by me.

🤖 Generated with Claude Code

fjvbn2003 avatar Oct 17 '26 10:10 fjvbn2003

The main reason of stuck on TCP DNS is: there is no effective timeout mechanism for TCP DNS so we need to reflect the timeout mechanism of UDP to TCP as well.

cosmo0920 avatar Oct 23 '26 09:10 cosmo0920