Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5074 Fix the WebSocket exception handling strategy #5075

Merged

Conversation

NilsRenaud
Copy link
Contributor

@NilsRenaud NilsRenaud commented Jan 18, 2024

Linked to this issue : #5074

The ConnectionBase exception handler was not set when webSocket.exceptionHandler(...) is called. This was leading ConnectionBase to consider the exception as uncaught and to print it, ignoring the exception handler set at the WebSocketImplBase level.

Moreover, this WebSocket handler was also called after the call to ConnectionBase#handleException(...).

So I decided to set the ConnectionBase exception handler with the WebSocketImplBase.

The replacement of Http1xConnectionBase conn with Http1xConnectionBase<?> conn was needed otherwise the compiler complains.

@vietj
Copy link
Member

vietj commented Jan 19, 2024

Your reasoning seems correct to me, however there are a few things we need to improve in this contribution

  1. you should address also the HTTP server case that I think will behave the same (looking at Http1xServerConnection)

  2. we should test that the related HttpConnection from where it is originating from is not reported the exception, i.e. any exception handler set before upgrading the HttpConnection to a WebSocket will never be called

  3. setting up the WebSocketImplBase#handleException as exception handler of HttpConnection will prevent uncaught exception from being logged, so instead of doing so, we could remove the WebSocketImplBase#exceptionHandler field and instead set the exception handler on WebSocketImplBase#conn when it is called (i.e. exceptionHandler(Handler<Throwable> handler) implementation becomes conn.exceptionHandler(handler). Doing this way we need to reroute internal calls reimplement WebSocketImplBase#handleException to delegate to conn#handleException

The ConnectionBase exception handler was not set when `webSocket.exceptionHandler(...)` is called. This was leading `ConnectionBase` to consider the exception as uncaught and to print it, ignoring the exception handler set at the WebSocketImplBase level.

Moreover, this WebSocket handler was also called after the call to `ConnectionBase#handleException(...)`.

So I decided to stick on the `ConnectionBase` exception handler for the WebSocketImplBase.

The replacement of `Http1xConnectionBase conn` with `Http1xConnectionBase<?> conn` was needed otherwise the compiler complains.

Signed-off-by: Nils Renaud <[email protected]>
@NilsRenaud NilsRenaud force-pushed the 5074_websocket_exception_handler branch from cd9f49d to b8904e0 Compare January 22, 2024 16:54
@vietj vietj added this to the 4.5.2 milestone Jan 24, 2024
@vietj vietj merged commit 9cfa7cb into eclipse-vertx:4.x Jan 24, 2024
7 checks passed
@vietj
Copy link
Member

vietj commented Jan 24, 2024

Great contrib @NilsRenaud ! can you port to master branch ?

@NilsRenaud
Copy link
Contributor Author

Thanks @vietj I'll do this

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.

2 participants