Skip to content

A client receiving an Object with more than 10 binary fields closes the connection #5504

@guillaume-mueller

Description

@guillaume-mueller

Describe the bug

When the Python or Node.js server sends an Object containing more than 10 binary fields to a web browser JS client got via NPM, it fails and the connection is interrupted.

The issue doesn't happen when the package is got via the CDN.

To Reproduce

Socket.IO server version: 4.8.3

Server

import { createServer } from 'http';
import { Server } from 'socket.io';

const PAYLOAD = Buffer.alloc(1); // Size doesn't matter

const httpServer = createServer();
const io = new Server(httpServer, {
    cors: { origin: "*" },
});

io.on('connection', (socket) => {
    console.log(`[socket ${socket.id}] connected`);

    socket.on('request_data', () => {
        socket.emit('data', {
            "1": PAYLOAD,
            "2": PAYLOAD,
            "3": PAYLOAD,
            "4": PAYLOAD,
            "5": PAYLOAD,
            "6": PAYLOAD,
            "7": PAYLOAD,
            "8": PAYLOAD,
            "9": PAYLOAD,
            "10": PAYLOAD,
            "11": PAYLOAD, // Commenting this line makes the issue disappear
        });
    });

    socket.on('disconnect', reason => {
        console.log(`[socket ${socket.id}] disconnected: ${reason}`);
    });
});

httpServer.listen(8000, 'localhost', () => {
    console.log('Server running at http://localhost:8000');
});

In Python with python-socketio 5.16.2 and uvicorn[standard] 0.48.0:

import socketio
import uvicorn

sio = socketio.AsyncServer(
    async_mode='asgi',
    cors_allowed_origins="*",
)

PAYLOAD = b"\x00" * 1  # Size doesn't matter

@sio.event
async def request_data(sid: str) -> None:
    await sio.emit('data', {
        "1": PAYLOAD,
        "2": PAYLOAD,
        "3": PAYLOAD,
        "4": PAYLOAD,
        "5": PAYLOAD,
        "6": PAYLOAD,
        "7": PAYLOAD,
        "8": PAYLOAD,
        "9": PAYLOAD,
        "10": PAYLOAD,
        "11": PAYLOAD,  # Commenting this line makes the issue disappear
    })

app = socketio.ASGIApp(sio)

if __name__ == '__main__':
    uvicorn.run(
        app,
        host='localhost',
        port=8000,
    )

Socket.IO client version: 4.8.3

Client

import { io } from 'socket.io-client';

const socket = io(`http://localhost:8000`);

socket.on('data', data => {
    console.log("Received data");
    console.log(data);
});

document.querySelector('#app').innerHTML = `
    <button id="requestData" type="button">Request Data</button>
`;

document.querySelector('#requestData').addEventListener(
    'click', () => socket.emit('request_data')
);
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>vite-project</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.ts"></script>
  </body>
</html>

Expected behavior

The message should be transmitted, showing in the browser console (F12), and the transport not disconnected.

Platform:

  • Device: x64 computer
  • OS: Linux Mint 22.3

Additional context

The issue does not happen via CDN:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test Socket.IO</title>
</head>
<body>
    <button id="requestData" type="button">Request Data</button>
    <script src="https://cdn.socket.io/4.8.3/socket.io.min.js"></script>
    <script>
        const socket = io('http://localhost:8000');

        document.getElementById('requestData').addEventListener('click', () => {
            socket.emit('request_data');
        });

        socket.on('data', data => {
            console.log("Received data");
            console.log(data);
        });
    </script>
</body>
</html>

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions