java Websocket closeHandler not being called sometimes

174 views
Skip to first unread message

nishan...@mettl.com

unread,
May 18, 2017, 10:30:33 AM5/18/17
to vert.x

Hi,

from our logic we are calling  ServerWebSocket.close(). sometimes it doesn't invoke closehandler.  
any idea? it's breaking our production logic.

Julien Viet

unread,
May 18, 2017, 12:12:50 PM5/18/17
to ve...@googlegroups.com
that can be a bug, do you have a reproducer ?

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/b964c679-52cd-4383-a4f5-cc678cf0bdc8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

nishan...@mettl.com

unread,
May 18, 2017, 10:34:46 PM5/18/17
to vert.x
Unfortunately no.
It comes in our production environment where around 50k odd WebSocket connections are created and closed daily. We can see this issue once a week.
we haven't encountered this issue in our testing or the stagging environment yet.

Julien Viet

unread,
May 19, 2017, 4:07:57 AM5/19/17
to ve...@googlegroups.com
do you know if that happens with normal termination or with abrupt close (like a reset) ?

Tim Fox

unread,
May 19, 2017, 4:14:26 AM5/19/17
to vert.x
Well... just because it's in your prod environment doesn't mean you can't create a reproducer :)

One way to approach this would be to add some debug/logging to discover the state of the app when the problem occurs, then reproduce that state in a test.

nishan...@mettl.com

unread,
May 21, 2017, 6:06:08 AM5/21/17
to vert.x
it happens with normal termination when I explicitly call ServerWebSocket.close().

Tim Fox

unread,
May 21, 2017, 8:09:23 AM5/21/17
to vert.x
You could try getting a stack dump when this occurs to see if there are any deadlocks.

nishan...@mettl.com

unread,
May 21, 2017, 11:22:36 AM5/21/17
to vert.x
thanks for your attention Tim.
will do that share my findings with the community.

nishan...@mettl.com

unread,
Jun 30, 2017, 2:29:03 AM6/30/17
to vert.x
we found the root cause of the issue
our code flow is as follows:
1. upgrade to WebSocket from https request.
2. perform some asynchronous initialization. (init method)
3. add the close handler.

Now if WebSocket is closed before adding close handler the close handler will never be called.

If I add closed handler just after opening WebSocket then a lot of state coordination needs to be done between onClose and init method.
Please suggest solution.

Tim Fox

unread,
Jun 30, 2017, 4:18:28 AM6/30/17
to vert.x
Yes, you need to set the close handler before the websocket is closed in order for it to be called. 

The same goes for any handler really, you need to set it before the event occurs in order to capture the relevant event.

nicolas.a...@etermax.com

unread,
Jun 30, 2017, 10:33:39 AM6/30/17
to vert.x
I think maybe I'm having a similar problem.
I execute some logic before adding the handler to prevent domain errors. So I pause the socket just when it was created and resume it after the logic was executed and the handler was set. But its seems that I'm losing events in some cases.

The code looks like:

private Handler<NetSocket> onConnect() {
return socket -> {
socket.pause()
;
String connectionId = socket.writeHandlerID();
execute(connectionId)
                .subscribe(() -> {
socket.handler(onStanzaReceiveHandler(connectionId))
.closeHandler(onCloseHandler(
connectionId));
socket.resume();
});
};
}

Is the pause/resume implemeted to work with this kind of logic ?

Tim Fox

unread,
Jun 30, 2017, 10:53:44 AM6/30/17
to vert.x
How is this related to the original question?

nicolas.a...@etermax.com

unread,
Jun 30, 2017, 11:20:53 AM6/30/17
to vert.x
You concluded that the handlers should be setted before any event ocurrs. So I thought that doing some stuff before the handler is set could end with the lost of a buffer. Its true that its not entirely related to the closeHandler so I apologize.

Tim Fox

unread,
Jul 1, 2017, 2:45:24 AM7/1/17
to vert.x
Do you have a reproducer for this? It would it easier for me to understand.

Tim Fox

unread,
Jul 2, 2017, 3:37:03 AM7/2/17
to vert.x
The reason I ask is it's not easy to understand from your snippet what you're trying to say :)


On Saturday, 1 July 2017 07:45:24 UTC+1, Tim Fox wrote:
Do you have a reproducer for this? It would it easier for me to understand.

Reply all
Reply to author
Forward
0 new messages