apache / apache/logging-log4j2
Syslog/Socket @ValidHost discards the appender on DNS miss at config load; reconnect never runs (Kubernetes late Service DNS; relates to LOG4J2-1047)
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.7k
- Avg merge
- 21h 30m
- Merged PRs (30d)
- 27
Description
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](https://issues.apache.org/jira/browse/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](https://issues.apache.org/jira/browse/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
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing SyslogAppender and Socket plugin construction through @ValidHost and the reconnection path, using the LOG4J2-1047 comparison in the issue. Reproduce the Kubernetes-style DNS miss, then verify that the appender remains available, retries after DNS appears, and still rejects an empty or malformed host.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kubernetes
- Domain
- backend, networking, observability-sre
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100