Bug 63114 - Async methods do not call handler on exception
Summary: Async methods do not call handler on exception
Status: RESOLVED INVALID
Alias: None
Product: Tomcat 9
Classification: Unclassified
Component: WebSocket (show other bugs)
Version: 9.0.14
Hardware: PC Linux
: P2 major (vote)
Target Milestone: -----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-25 13:18 UTC by Boris Petrov
Modified: 2019-01-29 10:41 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Boris Petrov 2019-01-25 13:18:28 UTC
While debugging another issue, we noticed that some (most?) async methods at least in WsRemoteEndpointImplBase do not call the handler when erring but rather throw an exception. Here are examples:

https://github.com/apache/tomcat/blob/TOMCAT_9_0_14/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java#L204

https://github.com/apache/tomcat/blob/TOMCAT_9_0_14/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java#L207

https://github.com/apache/tomcat/blob/TOMCAT_9_0_14/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java#L1224

https://github.com/apache/tomcat/blob/TOMCAT_9_0_14/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java#L799

These are coming from the "sendStringByCompletion" method. There's more async methods in this class and at least some of them have the same issues.

I think this is a bug. The SendHandler's onResult method should be called instead.
Comment 1 Mark Thomas 2019-01-28 20:07:11 UTC
The Java WebSocket spec requires IAE to be thrown when those methods are called with null data.
Comment 2 Boris Petrov 2019-01-29 05:08:17 UTC
Thank you for the response. But did you see all the links I pasted? The third and fourth one are throwing not for null-arguments but for other error cases. Are they according to the spec too?
Comment 3 Mark Thomas 2019-01-29 10:41:22 UTC
IllegalStateException on attempting to send messages concurrently is as per the spec.

IllegalArgumentException on encoding to UTF-8 shouldn't happen. It is possible but a client would need to go out of its way to trigger it. This case is not explicitly covered in the spec so implementations are free to make their own choice. Tomcat opted to treat this illegal input the same way the more common illegal input of null is handled.