Transport close when using 2.1.0 client send big message to 4.5.2 NodeJS server
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();
}
}
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)
So is there a way we can send a big payload now or will your fix be released in the near future?
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
maxHttpBufferSizelimit 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)
I have tried all methods you said:
- Increase
maxHttpBufferSize: in server i configuredmaxHttpBufferSizeto 1e8 ~ 100MB, it's much more bigger than 32MB but why i still faced thetransport closeerror - Force use WebSocket: i just tried
options.transport = new String[]{"websocket"}in java client but no change in result. Stilltransport 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
i have same problem but im using java server. have you found any solution ?
@conan13101998 were you able to figure out any solution for this?