Atmosphere / wasync

WebSockets with fallback transports client library for Node.js, Android and Java
http://async-io.org
161 stars 47 forks source link

Only the first of multiple messages are delivered when AtmosphereClient and TrackMessageSizeInterceptor are used #130

Closed slovdahl closed 7 years ago

slovdahl commented 9 years ago

Noticed this when updating from wAsync 1.4.3 to 2.1.2.

If multiple messages are delivered at the same time, which eg. happens when more than one message is cached by Atmosphere and delivered to a long-polling connection after it reconnects, only the first one is delivered to the Function<?> for Event.MESSAGE.

The cause of this seems to be that lines 175-177 in TranportsUtil are executed after the TrackMessageSizeDecoder has been executed:

for (Object m : l) {
    return matchDecoder(e, m, nd, decodedObjects);
}

In this case the l variable contains the decoded messages, and should be used instead of decodedObjects, which at this point always seems to be empty.

The reason it worked with earlier versions (eg. 1.4.3) is that the if statement on line 171 in TransportsUtil, nd.isEmpty(), was true unless any custom decoders had been added. After PaddingAndHeartbeatDecoder was added the statement will never be true any more, and that's probably when the bug started occuring.

slovdahl commented 9 years ago

I'll push a disabled unit test that verifies this as soon as I'm ready with it.

jfarcand commented 9 years ago

@slovdahl Any update?

slovdahl commented 9 years ago

I haven't been able to write a test that reproduces the behaviour and I haven't had enough time to try to learn how to. I'll try to find some time soon.

slovdahl commented 8 years ago

Finally got around to writing a test for this. I wasn't able to run any other tests in the suite and I had to use a newer version of testng (6.x) locally to even execute these ones in IntelliJ.

slovdahl commented 8 years ago

FYI, it works with 2.1.0. And this is the commit that broke it: https://github.com/Atmosphere/wasync/commit/9114ef32842433478b32c52b297fef4a6c133681