Skip to content

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

Description

@kaushiksrinivas

Description

Log4j2 SyslogAppender (and Socket) validates host with @ValidHost → InetAddress.getByName once at plugin build. If the name is syntactically fine but not in DNS yet (typical Kubernetes: collector Service created after the app JVM starts), configuration fail-closes:

java.net.UnknownHostException
The hostname is invalid
field 'host' has invalid value '…'
Null object returned for Syslog
Unable to locate appender "SYSLOG"

reconnectionDelayMillis, immediateFail, ignoreExceptions, and AsyncAppender do not help: there is no appender. monitorInterval only reloads if the config file mtime changes; it does not retry DNS by itself.

This matches LOG4J2-1047 (2015, still Open): When SyslogAppender can't find inetAddress at startup, it will never try to reconnect. Current 2.x surfaces the failure at @ValidHost (LOG4J2-1755 introduced that constraint; it is not a separate product bug).

Ask: do not use live DNS as “is this a valid host.” Reject empty/garbage host; on UnknownHostException, still create the appender and resolve on connect/reconnect (same idea as the 1047 patch).

Steps to reproduce
Log4j2 config with Syslog host = a DNS name that does not resolve, protocol=TCP, optional reconnectionDelayMillis=5000.
Start the JVM. Confirm the errors above; root logger has no SYSLOG.
Publish the DNS name (e.g. create the Kubernetes Service). Do not restart, do not change/touch the config file.
Keep logging.
Actual

SYSLOG never appears for that process. After DNS works, InetAddress.getByName would succeed, but Log4j2 never calls it again.

Expected

After DNS exists, Syslog connects (or retries) without a process restart or a forced config-file reload. A typo in host can still fail fast.

Environment
Log4j2 2.x 
Kubernetes: host = *.svc.cluster.local not present at JVM start, present seconds/minutes later

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions