[undertow-dev] Websocket: onMessage() called prior to onOpen()

Guruprasad Nagaraj gpn at networkart.com
Fri Jun 5 04:00:33 EDT 2015


Hi Stuart,
Yes, indeed. I can reproduce this all the time.

Here is a snippet from the wildfly console log -

==== WILDFLY STARTUP ====
13:01:55,848 INFO  [io.undertow.websockets.jsr] (MSC service thread 1-1) UT026003: Adding annotated server endpoint class com.NetworkArt.SVCentral.web.server.ws.agent.am.AMChannel for path /channel/am

==== ON STARTING REMOTE WEBSOCKET CLIENT ====
13:02:39,512 WARN  [AMChannel] (default task-3) msgRx(session-id: WhXpPiKFnU0l1rAUXkWExfVc) AUTH_REQ received in an unknown session, discarding
13:02:39,513 INFO  [AMChannel] (default task-3) forceClose(session-id: WhXpPiKFnU0l1rAUXkWExfVc)
13:02:39,883 INFO  [AMChannel] (default task-2) [acme] open( session-id: WhXpPiKFnU0l1rAUXkWExfVc) Added session
13:02:39,884 INFO  [AMChannel] (default task-2) [acme] close(session-id: WhXpPiKFnU0l1rAUXkWExfVc)

AMChannel is the annotated server endpoint, with open() and msgRx() as the onOpen and onMessage handlers respectively.

@ServerEndpoint(value = SVUrls.SVURL_FRAG_WS_CHANNEL_AM,
                configurator = WsConfigurator.class,
                encoders = {AMMsgEncoder.class},
                decoders = {AMMsgDecoder.class})
public class AMChannel {
...
}

WsConfigurator allows me to extract the host part of the FQDN in the connection url. acme.networkart.com<http://acme.networkart.com> would be the FQDN and WsConfigurator allows me to extract “acme” and put in the EndpointConfig userProperties.
AMMsgEncoder and AMMsgDecoder help in converting to an OutputStream and InputStream respectively.

session-id is the value retrieved from javax.websocket.Session getId().

AUTH_REQ is a message sent by the remote client post a successful connection with AMChannel.

forceClose() is a method in AMChannel that forces a session close. In the above snippet, as you see I am forcing a session close() since AMChannel hadn’t been called with open() earlier (which would be the point at which I would have recorded the session).

The remote client retries every 5 seconds post failure conditions. As I said earlier, some retries are again unsuccessful for the same reason, and sometimes they succeed.

I could put a workaround in the client to sleep for sometime before sending the first message to AMChannel, but I would like to see if the above issue can be solved before I do that.

Please let me know if you require any other information.

Thanks and Best Regards,
GPN

On 05-Jun-2015, at 11:12 am, Stuart Douglas <sdouglas at redhat.com<mailto:sdouglas at redhat.com>> wrote:

Do you have a way to reproduce this?

Stuart

Guruprasad Nagaraj wrote:
Wildfly version: 8.2.0.Final
Undertow version: 1.1.0.Final

Hi,
I am using Undertow web sockets.
A remote client (nopoll c client) attempts to open a websocket session;
the session is opened and the client immediately sends a message.
However, at the ServerEndpoint, the onMessage handler is called prior to
the onOpen handler.
My server side implementation rejects messages received prior to open
and even forces a session close.
The client retries the session, and sometimes it is successful i.e. I do
see an open first and then followed by a message by the client.

Is this an known issue?
Sorry, I couldn’t find a way to search the mailing-list archives.

Thanks and Best Regards,
GPN

_______________________________________________
undertow-dev mailing list
undertow-dev at lists.jboss.org<mailto:undertow-dev at lists.jboss.org>
https://lists.jboss.org/mailman/listinfo/undertow-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20150605/b44c1fb9/attachment-0001.html 


More information about the undertow-dev mailing list