Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
conan13101998 opened this issue Oct 19, 2022 · 6 comments
Labels

Comments

@conan13101998
Copy link

conan13101998 commented Oct 19, 2022

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
Copy link
Member

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

@conan13101998
Copy link
Author

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

@darrachequesne
Copy link
Member

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:

  • increase the maxHttpBufferSize limit of the server
  • add a delay between several bit emits (so that each packet is sent in its own HTTP request)
  • or force the client to use WebSocket (with the transports option)

@conan13101998
Copy link
Author

conan13101998 commented Oct 19, 2022

I have tried all methods you said:

  • Increase maxHttpBufferSize: in server i configured maxHttpBufferSize to 1e8 ~ 100MB, it's much more bigger than 32MB but why i still faced the transport close error
  • Force use WebSocket: i just tried options.transport = new String[]{"websocket"} in java client but no change in result. Still transport close
  • Add a delay between emits: Use semaphore to wait till the message is delivered to server or timeout before emit next message also can't solve the problem

@ixi0n3k
Copy link

ixi0n3k commented Dec 11, 2023

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

@Rits1272
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants