Fix: ensure activeConnection is closed on error by madwind · Pull Request #1127 · rsocket/rsocket-java

Fix: ensure activeConnection is closed after sending error

Motivation:

When integrating with Spring Security over RSocket, if authentication or authorization fails, the server emits an error internally but does not actually send it to the client.
At the same time, the activeConnection is kept open, leaving the client with no response and the server holding a dangling connection.

Modifications:

Added a call to activeConnection.sendErrorAndClose(rSocketErrorException) so that the error is delivered to the client and the connection is properly closed.

Result:

On authentication/authorization failure, the client will now receive an error instead of hanging indefinitely.

The connection will also be closed, preventing resource leaks and inconsistent states.