Skip to content

Expected binary marker in the payload #2

Description

@funkyjive

This issue might be an issue with socket.io itself, but I have only ever produced it using socket.io-server-java. It can be recreated using the chat sample that comes with this code.

Steps to reproduce:
1. Modify chat.html so that it declares xhr polling as the transport. This problem is specific to xhr polling (which is what I need to use for my project for various reasons)

      var socket = io('http://localhost:8080/chat', {
       transports: ['polling']
//       transports: ['websocket']
       });

2. run ChatServer
3. browse to http://localhost:8080/chat.html
4. put /rbinary in over and over again, while watching the log console

Sooner or later, you'll have this exception show up in the logs:
com.codeminders.socketio.server.SocketIOProtocolException: Expected binary marker in the payload
at ... EngineIOProtocol.binaryDecodePayload(EngineIOProtocol.java:299)
And the Socket.IO connection will be terminated and re-established.

There doesn't appear to be any predictability on when the communication will fail. Sometimes it happens first, sometimes it takes a few /rbinary commands to get it to happen.

The code here is clearly where the exception occurred:

com.codeminders.socketio.protocol.EngineIOProtocol
public static List<EngineIOPacket> binaryDecodePayload(InputStream is)
        throws IOException
{
    ArrayList<EngineIOPacket> packets = new ArrayList<>();
    if(is.read() != 1)
        throw new SocketIOProtocolException("Expected binary marker in the payload");

}

I dug in a bit and I learned a few things by going through with a debugger in both Chrome and Firefox and in Java and I learned a few things.

  • The binary begins with a 1 for all the request where everything works. For the one with a problem, it will begin with a 0 (which triggers the error).

  • What appears to be happening is that socket.io combines multiple sends into a single binary send. A functional send will follow something like this:


[TEXT POST] 25:42/chat,["server binary"]
[TEXT POST] 42:461-/chat,4[{"_placeholder":true,"num":0}]
[BINARY POST] ��ÿ�����   (binary blob)

but when it goes wrong it looks something like this (unfortunately Firefox won't let me copy directly):

[TEXT POST] 25:42/chat,["server binary"]
[BINARY POST] [binarystuffhere]ÿ461-/chat,0[{"_placeholder":true,"num":0}][binarystuffhere]

I copied the latest socket.io.js (1.7.2) down from:
https://github.com/socketio/socket.io-client/blob/master/dist/socket.io.js
and ran with it, and it seemed to have the same problem.

Is this an issue with socket.io creating an invalid message? Or is this an issue with socket.io-server-java not being able to parse a valid message?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions