socketio / socket.io-client-java

Full-featured Socket.IO Client Library for Java, which is compatible with Socket.IO v1.0 and later.
https://socketio.github.io/socket.io-client-java/installation.html
Other
5.31k stars 969 forks source link

Transport close when using 2.1.0 client send big message to 4.5.2 NodeJS server #726

Open conan13101998 opened 1 year ago

conan13101998 commented 1 year ago

Describe the bug When i try to send message to NodeJS Socket.io Server, small message (< 32MB) is succeed but when payload more than 32MB => disconnect event fired with reason transport close. Sometime it send 1st big message succeed and another fail because timeout (client auto reconnect after disconnected)

Note: I also implemented ACK in both server and client

To Reproduce

Socket.IO server version: 4.5.2 with Express

Server

import { Server } from "socket.io";

const io = new Server(http, {
    cors: {
        origin: "*"
    },
    maxHttpBufferSize: 1e8,
    pingTimeout: 60000,
    pingInterval: 60000,
    upgradeTimeout: 30000,
    transport: ["websocket", "polling"]
})

Socket.IO java client version: 2.1.0

Client

public class MyApplication {
    public static void main(String[] args) throws URISyntaxException {
        IO.Options options = IO.Options.builder().build();
        Socket socket = IO.socket("http://localhost:8081", options);
        socket.connect();
        socket.on(Socket.EVENT_DISCONNECT, msg -> log.info("Disconnected with socket server. Reason: {}", msg));
    String msg = generateStringSize(1024 * 1024 * 32);
    for(int i=0; i<10; i++) {
        socket.emit("test", msg, new AckWithTimeout(20000) {
            @Override
            public void onSuccess(Object ...args) {
                log.info("Send succeed");
            }

            @Override
            public void onTimeout() {
                log.info("Send failed");
            }
        });
    }
    socket.close();
    }

    private String generateStringSize(int bytes) {
        StringBuilder builder = new StringBuiler;
        for(int i=0; i<bytes/2; i++) {
            builder.append("a");
        }
        return builder.toString();
    }
}
darrachequesne commented 1 year ago

Hi! You are right, we need to take in account the maxPayload field sent by the server, like the JS client: https://github.com/socketio/engine.io-client/commit/46fdc2f0ed352b454614247406689edc9d908927 (added in version 4.5.0)

conan13101998 commented 1 year ago

So is there a way we can send a big payload now or will your fix be released in the near future?

darrachequesne commented 1 year ago

The problem here is that when the client is using HTTP long-polling, the packets are concatenated and the total size is over the maxHttpBufferSize limit of the server.

So as a workaround you can either:

conan13101998 commented 1 year ago

I have tried all methods you said:

ixi0n3k commented 8 months ago

i have same problem but im using java server. have you found any solution ?

Rits1272 commented 3 months ago

@conan13101998 were you able to figure out any solution for this?