Skip to content

UndertowWebsocket close #2565

Closed
Closed

Description

@U1F984

The undertow websocket implementation close doesn't appear to actually close the connection, it just calls the close handler. Additionally it doesn't check if the websocket session is already closed, which can easily result in infinite recursion (e.g. onClose calling a cleanup function also called by onError, which then calls close).

Activity

  1. added this to the 2.13.1 milestone on Apr 26, 2022
  2. jknack commented on Apr 26, 2022

    @jknack
    Member

    Thank you, this bug was across all servers.

  3. U1F984 commented on Apr 28, 2022

    @U1F984
    ContributorAuthor

    Hi, thanks for the super fast fix.

    Unfortunately the infinite recursion is still an issue:

    	at io.jooby.internal.utow.UtowWebSocket.onError(UtowWebSocket.java:230)
    	at io.jooby.internal.utow.UtowWebSocket$1.onError(UtowWebSocket.java:255)
    	at io.jooby.internal.utow.UtowWebSocket$1.onError(UtowWebSocket.java:251)
    	at io.undertow.websockets.core.WebSockets.sendInternal(WebSockets.java:915)
    	at io.undertow.websockets.core.WebSockets.sendInternal(WebSockets.java:900)
    	at io.undertow.websockets.core.WebSockets.sendClose(WebSockets.java:856)
    	at io.undertow.websockets.core.WebSockets.sendClose(WebSockets.java:831)
    	at io.jooby.internal.utow.UtowWebSocket.handleClose(UtowWebSocket.java:250)
    	at io.jooby.internal.utow.UtowWebSocket.close(UtowWebSocket.java:139)
    	at foo.AbstractWebsocketHandler$PostInit.onError(AbstractWebsocketHandler.kt:93)
    	at foo.AbstractWebsocketHandler.handle$lambda-4$lambda-2(AbstractWebsocketHandler.kt:35)
    

    With the AbstractWebsocketHandler having this:

     configurer.onError { ws, throwable -> foo.onError(ws, throwable) }
    // foo:
    ws.close(WebSocketCloseStatus.SERVER_ERROR)

    Maybe calling IoUtils.safeClose(channel) before calling the error handler in io.jooby.internal.utow.UtowWebSocket#handleClose#WebSocketCallback#onError would fix it? As far as I can see that should immediately set org.xnio.Connection#state so that io.jooby.internal.utow.UtowWebSocket#isOpen will return false.

    The actual exception is

    java.io.IOException: UT002002: Channel is closed
    	at io.undertow.websockets.core.WebSocketChannel.send(WebSocketChannel.java:343)
    	at io.undertow.websockets.core.WebSockets.sendInternal(WebSockets.java:906)
    	at io.undertow.websockets.core.WebSockets.sendInternal(WebSockets.java:900)
    	at io.undertow.websockets.core.WebSockets.sendClose(WebSockets.java:856)
    	at io.undertow.websockets.core.WebSockets.sendClose(WebSockets.java:831)
    	at io.jooby.internal.utow.UtowWebSocket.handleClose(UtowWebSocket.java:250)
    	at io.jooby.internal.utow.UtowWebSocket.close(UtowWebSocket.java:139)
    
  4. modified the milestones: 2.14.0, 2.14.1 on Apr 28, 2022
  5. reopened this on Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions