jenkinsci / jenkinsci/syslog-java-client
NullPointerException when closing the TCP socket before the first message is sent
- Dominant language
- Java
- Stars
- 91
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
### Jenkins and plugins versions report
We're using the `TcpSyslogMessageSender` to send audit logs in the `RFC5424` format to a local rsyslog server.
Our service creates an instance of `TcpSyslogMessageSender` when it starts and begins emitting events once the start-up procedure has been completely successful.
In cases where our service is shutdown before the first audit event is dispatched, we've noticed that the [close method](https://github.com/jenkinsci/syslog-java-client/blob/8ed62dc22f8531cac3f19e6f541eddbd304062cf/src/main/java/com/cloudbees/syslog/sender/TcpSyslogMessageSender.java#L290) on the `TcpSyslogMessageSender` can throw a null point exception as the socket hasn't been assigned yet and is indeed null at that stage.
There are other parts of this class that leverage [com.cloudbees.syslog.util.IoUtils#closeQuietly](https://github.com/jenkinsci/syslog-java-client/blob/8ed62dc22f8531cac3f19e6f541eddbd304062cf/src/main/java/com/cloudbees/syslog/util/IoUtils.java#L31C24-L31C36), which looks like a suitable solution to this issue.
Keen to get your thoughts on this,
Thanks
### What Operating System are you using (both controller, and any agents involved in the problem)?
Error happening on a Windows Feature Experience Pack 1000.19053.1000.0
### Reproduction steps
1. Create a project using `com.cloudbees:syslog-java-client:1.1.7`
2. Create an instance of `TcpSyslogMessageSender`
3. Invoke the `close()` method on the `TcpSyslogMessageSender` instance
### Expected Results
Not exception to be thrown
### Actual Results
Null pointer exception is thrown
### Anything else?
_No response_
### Are you interested in contributing a fix?
Happy to contribute and fix this issue if the solution is adequate enough
Contributor guide
Assessment
This issue has not been assessed yet.