logback icon indicating copy to clipboard operation
logback copied to clipboard

LOGBACK-1557 - An exception is thrown when AbstractServerSocketAppender is being stopped

Open multicatch opened this issue 4 years ago • 0 comments

This is a pull request related to LOGBACK-1557

ServerSocketAppender (or any appender using ConcurrentServerRunner) can emit an error when stopping. This issue is most noticeable in projects where Spring Boot is used, as Spring Boot reloads Logback config when starting and any error that occured during this reload is escalated and crashes the whole app.

Symptoms

An error containing the following message is being reported to StatusManager:

java.net.SocketException: Socket is closed

How to reproduce?

I have added a simple test that presents how to reproduce the error:

https://github.com/multicatch/logback/commit/b41a33b1ed717ed282955631f23b68dba821add5

The cause

This is due to the fact that ConcurrentServerRunner is not being interrupted when it is run by the ExecutionService and it waits for new connections even when it was instructed to stop. Finally, the ServerSocket is closed and the accept() method is still waiting for connections (and even if not, the loop in ConcurrentServerRunner is not breaking because the thread with the runner was not interrupted) and it causes the SocketException. It is then caught and added to StatusManager, and then crashes Spring Boot as this is treated as configuration error.

I have implemented a fix for this issue (https://github.com/multicatch/logback/tree/fix/server-socket-closing) and it can be cherry-picked to all affected versions.

multicatch avatar May 15 '21 13:05 multicatch