Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-3490

Websocket onClosed not called on idle timeout

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 8.1.0.Final
    • Fix Version/s: 9.0.0.Alpha1
    • Component/s: Web Sockets
    • Labels:
      None
    • Environment:

      Wildfly 8.1.0 Final on Linux (Centos/Fedora)

      Description

      When implementing a JSR-356 websocket endpoint I set

      session.setMaxIdleTimeout(5000);

      in the @OnOpen method. This means that, if no traffic is generated on the websocket in five seconds, the websocket is automatically closed.

      Now, if the websocket si correcly closed by the client calling the "close" method in JS, the corrispective @OnClose method on the endpoint is called. But if the websocket is closed because of the idle timeout, on the server the @OnClose method is not called, and also @OnError method isn't called.

      I think the correct behaviour should be to call @OnClose even when the socket is closed because of the idle timeout, so that the application has the ability to make some cleanup. Also, this is the behaviour I see when deploying in other Java web/application server.

      The test code of my endpoint is the following:

      EchoEndpoint.java
      @ServerEndpoint("/ws/echo")
      public class EchoEndpoint {
          
          @OnMessage
          public String onMessage(String message) {
              System.out.println("RECV: " + message);        
              return message;
          }
      
          @OnOpen
          public void onOpen(Session session) {
              session.setMaxIdleTimeout(5000);
              System.out.println("OPEN");
          }
      
          @OnClose
          public void onClose() {
              System.out.println("CLOSE");
          }
      
          @OnError
          public void onError(Throwable t) {
              System.out.println("ERROR");
          }  
      }
      

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                swd847 Stuart Douglas
                Reporter:
                ecolombo Emanuele Colombo
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: