Bug 57762 - WebSocket client doesn't detect forceful connection failures
Summary: WebSocket client doesn't detect forceful connection failures
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: WebSocket (show other bugs)
Version: 8.0.20
Hardware: PC All
: P2 normal (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2015-03-26 00:32 UTC by palmercox
Modified: 2015-03-28 21:55 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description palmercox 2015-03-26 00:32:07 UTC
It appears that the WebSocket client can't detect when a connection is forcefully closed. Given the following example program:

public class App2 {
    public static class Client {
        public void onClose() {
        public void onError(Throwable t) {
        	System.out.println("ERROR: " + t);

    public static void main(final String[] args) throws Exception {
        final WebSocketContainer container = ContainerProvider.getWebSocketContainer();
        System.out.println("Container: " + container);

I then modified /etc/hosts so that echo.websocket.org resolved to localhost. I then set up an SSH tunnel to direct local port 80 to echo.websocket.org (which is

sudo ssh me@someserver -L 80:

I then started the program. It connected. Next, I killed the SSH session. Neither the onClosed on onError methods were invoked.

When I tested the same program running on Tyrus 1.10, however, onClose was invoked with a CloseReason 10006 - Closed Abnormally.

I think the Tyrus behavior is correct - the socket is dead and the program should be notified.
Comment 1 palmercox 2015-03-26 00:36:12 UTC
I tested this on Tomcat 8.0.20.
Comment 2 Remy Maucherat 2015-03-26 09:30:55 UTC
The NIO2 code that the client uses looks ok to me (WsFrameClient) and should work unless there's a JVM or platform issue. If the JVM doesn't report that the socket is gone using the failed of the completion handler, then nothing is going to happen and it would be the behavior you see.

Although this should be tested to make sure this is indeed the explanation, it's possible there's no Tomcat bug to fix here.
Comment 3 palmercox 2015-03-26 14:24:02 UTC
For reference, I tested on Mac OS X 10.10.2 and Java 1.8.0_40. I haven't had a chance to check if there is a JVM issue.
Comment 4 Mark Thomas 2015-03-28 21:55:06 UTC
Interesting. The NIO2 code reports a dropped connection as a successful read for EOF. Not what was expected. This is now correctly handled in trunk, 8.0.x (for 8.0.22 onwards) and 7.0.x (for 7.0.62 onwards).