Fix: ensure activeConnection is closed on error #1127
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.