Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-6103

Synchronization on JSR 356 connection


    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 7.2.0
    • Fix Version/s: 7.3.0, 8.0.0-M1
    • Labels:
    • Environment:
      Tomcat 7.0.59, java8


      Recently I ran into a strange error in our Wicket application that uses Wicket's native WebSockets:

      java.lang.IllegalStateException: The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method
      	at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1175)
      	at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.textStart(WsRemoteEndpointImplBase.java:1138)
      	at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendString(WsRemoteEndpointImplBase.java:192)
      	at org.apache.tomcat.websocket.WsRemoteEndpointBasic.sendText(WsRemoteEndpointBasic.java:37)
      	at org.apache.wicket.protocol.ws.javax.JavaxWebSocketConnection.sendMessage(JavaxWebSocketConnection.java:81)
      	at org.apache.wicket.protocol.ws.api.WebSocketResponse.close(WebSocketResponse.java:92)
      	at org.apache.wicket.protocol.ws.api.AbstractWebSocketProcessor.broadcastMessage(AbstractWebSocketProcessor.java:252)
      	at org.apache.wicket.protocol.ws.api.AbstractWebSocketConnection.sendMessage(AbstractWebSocketConnection.java:43)

      As far as I understand the problem, we are trying to send more messages through one connection at the same time. Since we push messages on connections from background services/threads, this is very likely.

      Looking at the JSR 356 API I was found that

      If the websocket connection underlying this RemoteEndpoint is busy sending a message when a call is made to send another one, for example if two threads attempt to call a send method concurrently, or if a developer attempts to send a new message while in the middle of sending an existing one, the send method called while the connection is already busy may throw an IllegalStateException.

      I think that using synchronized versions of JavaxWebSocketConnection.sendMessage.. methods would be great idea.




            • Assignee:
              mgrigorov Martin Grigorov
              jan-krakora Jan Krakora
            • Votes:
              0 Vote for this issue
              3 Start watching this issue


              • Created: