ReactiveX / RxNetty

Reactive Extension (Rx) Adaptor for Netty
Apache License 2.0
1.38k stars 254 forks source link

(0.5.x) First message received right after connecting to WebSocket seems to be missing #560

Open sokolas opened 8 years ago

sokolas commented 8 years ago

I have a piece of code very similar to the example EchoClient example

Here it is:

        HttpClient.newClient("gateway.discord.gg", 443)
            .unsafeSecure().createGet("/?encoding=json&v=5")
            .requestWebSocketUpgrade()
            .doOnNext(resp -> logger.info(resp.toString()))
            .flatMap(resp -> resp.getWebSocketConnection())
            .flatMap(conn -> conn.getInput())
    .toBlocking().forEach(f -> logger.info(f.content().toString(Charset.defaultCharset())));

When connected, the client should receive a message from the server, like this: {"t":null,"s":null,"op":10,"d":{"heartbeat_interval":41250,"_trace":["discord-gateway-prd-1-12"]}}

A working example can be found here: WebSocket example (jsfiddle) - run it and look in the browser console for its output. This is to ensure the server sends me data upon connecting.

What I get with my Java code, though, is a warning from netty:

WARN io.reactivex.netty.protocol.http.internal.AbstractHttpConnectionBridge - Data received on channel, but no subscriber registered. Discarding data. Message class: io.netty.handler.codec.http.websocketx.TextWebSocketFrame, channel: [id: 0x905dd524, L:/10.100.42.2:51728 - R:gateway.discord.gg/104.16.59.37:443]

What am I doing wrong here?

NiteshKant commented 7 years ago

@sokolas sorry haven't got time yet to dig more into this but the issue is with Ws7To13UpgradeHandler in which while removing HttpClientCodec, the message buffered in the codec is emitted first before the HTTP headers.

rstoyanchev commented 7 years ago

I've encountered this as well. Looking at Netty's WebSocketClientHandshaker by comparison it delays the removal of the HttpClientCodec.