Skip to content

Keep socket appenders when the host is not resolvable yet - #4462

Open
vindeckyy wants to merge 1 commit into
apache:2.xfrom
vindeckyy:fix/4309-defer-host-resolution
Open

vindeckyy wants to merge 1 commit into
apache:2.xfrom
vindeckyy:fix/4309-defer-host-resolution

Conversation

@vindeckyy

Copy link
Copy Markdown
Contributor

Fixes #4309.

@ValidHost and TcpSocketManagerFactory both treat a host that does not resolve now as invalid, so the appender is discarded at configuration time. A host that only appears in DNS later (a Kubernetes Service created after the JVM starts) never recovers without a restart, and reconnectionDelayMillis cannot help because no appender or manager is left.

Changes

  • ValidHostValidator still rejects null, empty, malformed names and out-of-range IPv4 literals, but accepts a syntactically valid host name that does not resolve yet and logs a warning. The name is resolved when connecting.
  • TcpSocketManagerFactory no longer returns null on UnknownHostException when a reconnection delay is configured; it creates a manager with no socket and lets the existing Reconnector resolve the host on every attempt. Appenders always get a delay (getSocketManager defaults it to 30s), so this also covers default configurations.
  • DatagramSocketManager/DatagramOutputStream resolve the host on the first datagram instead of failing construction, and retry while the host stays unresolved.
  • AbstractSocketManager#getContentFormat falls back to the host name while no address is known.
  • Updated the @ValidHost Javadoc and the plugin manual.

Tests

SocketAppenderReconnectTest#unresolvable_host_should_be_resolved_on_reconnect fails before the change (appender dropped for an unresolvable host) and passes after it. ValidHostValidatorTest covers the accepted and rejected names, and DatagramOutputStreamTest covers the UDP retry path.

Targeted run: 82 tests in SocketAppender*Test, SyslogAppender*Test, Tls*Test, SslSocketManagerTest, ValidHostValidatorTest, DatagramOutputStreamTest, 0 failures. spotless:check passes.

Socket and syslog appenders were dropped when the configured host did not
resolve at configuration time, so a host that only appeared in DNS later
(a Kubernetes Service created after the JVM starts, for example) never
recovered without a restart.

Accept a syntactically valid host name that does not resolve yet, and let
the existing reconnector resolve it again on every attempt. UDP appenders
keep the host unresolved and retry it on each datagram.
@ramanathan1504 ramanathan1504 added appenders Affects one or more Appender plugins bug Incorrect, unexpected, or unintended behavior of existing code java Pull requests that update Java code port-to-main labels Nov 7, 2026
@ramanathan1504 ramanathan1504 added this to the 2.27.0 milestone Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

appenders Affects one or more Appender plugins bug Incorrect, unexpected, or unintended behavior of existing code java Pull requests that update Java code port-to-main

Projects

Development

Successfully merging this pull request may close these issues.

Syslog/Socket @ValidHost discards the appender on DNS miss at config load; reconnect never runs (Kubernetes late Service DNS; relates to LOG4J2-1047)

2 participants