-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Socket disconnects on big payload. #5140
Comments
please ! |
Hi! I see you are using NestJS, did you increase the body parser size limit? Reference: https://docs.nestjs.com/faq/raw-body#body-parser-size-limit |
Yes i have set bodyparser limit as well. this is my main.ts file `
` |
Large packets will cause timeout so you need to split the data to multiple packets. This approach is also good for not to block event loop which often happens with large data. I believe this should be addressed in socket.io level as devs are still wondering this issue. If nothing else, just console warning when the packet is likely too big. |
That's understandable for maybe files that are huge in size but a 700KB or 800KB shouldn't need breaking down. no? |
@llaakso are you ref like this? ![]() |
@faisal-anwar825 @Malikrehman00107 unfortunately I was not able to reproduce the issue: https://github.com/socketio/socket.io/tree/main/examples/nestjs-example
socket.on("connect", () => {
// [...]
socket.emit("big file", "a".repeat(1e7)); // 10 MB
});
@WebSocketGateway({
maxHttpBufferSize: 1e8
})
export class EventsGateway {
// [...]
@SubscribeMessage('big file')
handleBigFile(@MessageBody() data: string): void {
console.log("received", data.length);
}
} Same with the @WebSocketGateway({})
export class EventsGateway {
// [...]
async onModuleInit() {
this.server.engine.opts.maxHttpBufferSize = 1e8;
}
@SubscribeMessage('big file')
handleBigFile(@MessageBody() data: string): void {
console.log("received", data.length);
}
}
@llaakso I guess we could indeed split big payloads into several chunks. Maybe as a custom parser? What do you think? Reference: https://socket.io/docs/v4/custom-parser/ |
@darrachequesne we are still facing the issue so I belive the idea from @llaakso is a good one! we are going to try and will surely update in case it works. best |
I am using socket.io to create a realtime chat which includes attachments as well. I am sending files in Base64 form. but the issue is that if file size is around 500 to 600 KB. it gets send successfully but when file size increases more than that the sockets disconnects as soon as i send the message, with the error
i have tried increasing the maxHttpBufferSize to 1MB and 100MB but still files > 7, 800 KBs wont upload.
Socket.IO server version:
4.7.2
This is the code from my server
`
`
The text was updated successfully, but these errors were encountered: