[undertow-dev] Handling termination of WebSocket connection

Stuart Douglas sdouglas at redhat.com
Tue Oct 21 16:29:53 EDT 2014


So what you are probably seeing is that without receives resumed Undertow does not get notification of the underlying connection failure (i.e. it does not receive the close message or does not see read() returning -1).

Unfortunately  I am not sure if there is much we can do here. I guess we could just read anyway and discard all the messages, but that seems silly. 

Stuart

----- Original Message -----
> From: "Vladimir Tsukur" <flushdia at gmail.com>
> To: "Stuart Douglas" <sdouglas at redhat.com>
> Cc: undertow-dev at lists.jboss.org
> Sent: Wednesday, 22 October, 2014 12:10:49 AM
> Subject: Re: [undertow-dev] Handling termination of WebSocket connection
> 
> Thanks Stuart,
> 
> Did not see this method in 1.0.x since it was added at a later release -
> tried with latest version and it works well.
> 
> However, I figured out that connection termination works well iif receive
> setter is set:
> 
>     WebSocketChannel channel = ...;
>     channel.getReceiveSetter().set(new AbstractReceiveListener() {});
>     channel.addCloseTask(new ChannelListener<WebSocketChannel>() {
>         @Override
>         public void handleEvent(WebSocketChannel channel) {
>             ...
>         }
>     });
> 
> If receive setter is not set, then close task will not be called. In my
> case there was no intent to receive messages from the client and just push
> them from the server. Receive setter was not set => connection was not
> closed.
> 
> It seems obligatory to set receive setter all the time to make the thing
> work. Is it intended? While it is not a big deal really, I would imagine
> that Undertow should handle connection termination without explicit receive
> setter call made by the API client.
> 
> 
> On Tue, Oct 21, 2014 at 2:08 AM, Stuart Douglas <sdouglas at redhat.com> wrote:
> 
> > WebsocketChannel.addCloseTask() should do what you are after (this is
> > actually provided by the base AbstractFramedChannel class).
> >
> > Stuart
> >
> > ----- Original Message -----
> > > From: "Vladimir Tsukur" <flushdia at gmail.com>
> > > To: undertow-dev at lists.jboss.org
> > > Sent: Tuesday, 21 October, 2014 7:20:54 AM
> > > Subject: [undertow-dev] Handling termination of WebSocket connection
> > >
> > > Let's imagine user closed browser tab and thus terminated WebSocket
> > > connection. Is there any way to run a callback method on the server-side
> > to
> > > handle this case?
> > >
> > > The requirement is to perform necessary cleanup actions when connection
> > is
> > > closed, regardless of the type of disconnect (normal, forced termination,
> > > etc.).
> > >
> > > (Ideally using lower level API, and not JSR 356)
> > >
> > > --
> > > Vladimir Tsukur
> > > Software Architect, Design Engineer
> > >
> > > _______________________________________________
> > > undertow-dev mailing list
> > > undertow-dev at lists.jboss.org
> > > https://lists.jboss.org/mailman/listinfo/undertow-dev
> >
> 
> 
> 
> --
> Vladimir Tsukur
> Software Architect, Design Engineer
> 


More information about the undertow-dev mailing list