Skip to content

Connect SyslogOutputStream's DatagramSocket to the syslog host (#939) - #1076

Merged
ceki merged 1 commit into
qos-ch:masterfrom
Lyin-OTTF:fix/939-syslog-socket-connect
Oct 19, 2026
Merged

ceki merged 1 commit into
qos-ch:masterfrom
Lyin-OTTF:fix/939-syslog-socket-connect

Conversation

@Lyin-OTTF

Copy link
Copy Markdown
Contributor

SyslogOutputStream creates its DatagramSocket with the no-arg constructor, which binds an ephemeral port on the wildcard address. The appender holds that socket for its whole lifetime, so hardened environments observe an unconnected UDP listener on all interfaces (ss -ulnp) for as long as the application runs - exactly the "random ports getting (and remaining) open" from the issue.

This stream only ever sends datagrams to one host:port, so the socket is now connected to that address in the constructor:

  • a connected UDP socket is reported by ss as connected to its peer instead of listening on the wildcard, which removes the exposure;
  • the OS still selects the source address per routing table, so remote syslog targets keep working;
  • send() is unchanged - every packet already targets exactly the connected address.

The issue's suggestion of binding the socket to localhost was deliberately not followed: datagrams sourced from a loopback address are dropped by remote syslog receivers, which would break every non-local configuration.

SyslogOutputStreamTest (new) asserts the connected state and, against a real local DatagramSocket, that flush() still delivers the datagram to the receiving socket. Existing behavior is otherwise untouched; close() still releases the socket.

Verification: Windows, JDK 21. mvn -pl logback-core test -Dtest=SyslogOutputStreamTest passes (2/2); reverting only SyslogOutputStream fails the connected-state test.

Closes #939

…h#939)

SyslogOutputStream created its DatagramSocket with the no-arg constructor,
which binds an ephemeral port on the wildcard address. The appender holds
that socket for its whole lifetime, so hardened environments see an
unconnected UDP listener on all interfaces (ss -ulnp) for as long as the
application runs.

This stream only ever sends datagrams to one host:port, so the socket is
now connected to that address. A connected UDP socket is reported as
connected to its peer instead of listening on the wildcard, while the OS
still selects the source address per routing table - remote syslog targets
are unaffected. The issue's suggestion of binding to localhost was not
followed, as loopback-sourced packets are dropped by remote receivers.

SyslogOutputStreamTest asserts the connected state and, on a real local
DatagramSocket, that flush() still delivers the datagram.

Closes qos-ch#939
@ceki
ceki merged commit 619e102 into qos-ch:master Oct 19, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SyslogOutputStream opens DatagramSocket bind on wildcard address

2 participants