-
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
v3 and v4 close socket if more than 1MB is sent (but v2 is fine) #3946
Comments
Yes, this is expected, the const io = require("socket.io")(httpServer, {
maxHttpBufferSize: 1e8
}); Reference: |
Thanks for the quick reply! Can you possibly consider converting this from bug report to feature request? |
Yes, we could indeed make the error more user-friendly 👍 Possibly linked: #3237 |
The close event will now include additional details to help debugging if anything has gone wrong. Example when a payload is over the maxHttpBufferSize value in HTTP long-polling mode: ```js socket.on("close", (reason, details) => { console.log(reason); // "transport error" // in that case, details is an error object console.log(details.message); "xhr post error" console.log(details.description); // 413 (the HTTP status of the response) // details.context refers to the XMLHttpRequest object console.log(details.context.status); // 413 console.log(details.context.responseText); // "" }); ``` Note: the error object was already included before this commit and is kept for backward compatibility Example when a payload is over the maxHttpBufferSize value with WebSockets: ```js socket.on("close", (reason, details) => { console.log(reason); // "transport close" // in that case, details is a plain object console.log(details.description); // "websocket connection closed" // details.context is a CloseEvent object console.log(details.context.code); // 1009 (which means "Message Too Big") console.log(details.context.reason); // "" }); ``` Example within a cluster without sticky sessions: ```js socket.on("close", (reason, details) => { console.log(details.context.status); // 400 console.log(details.context.responseText); // '{"code":1,"message":"Session ID unknown"}' }); ``` Note: we could also print some warnings in development for the "usual" errors: - CORS error - HTTP 400 with multiple nodes - HTTP 413 with maxHttpBufferSize but that would require an additional step when going to production (i.e. setting NODE_ENV variable to "production"). This is open to discussion! Related: - socketio/socket.io#3946 - socketio/socket.io#1979 - socketio/socket.io-client#1518
Closed by socketio/engine.io-client@b9252e2, included in socket.on("close", (reason, details) => {
console.log(reason); // "transport error"
// in that case, details is an error object
console.log(details.message); "xhr post error"
console.log(details.description); // 413 (the HTTP status of the response)
// details.context refers to the XMLHttpRequest object
console.log(details.context.status); // 413
console.log(details.context.responseText); // ""
}); Please reopen if needed! |
Describe the bug
Steps to reproduce
1e6
in size (code sample below)Code Sample
Socket.IO server version:
4.1.2
Server
Socket.IO client version:
4.1.2
Client
Expected behavior
Don't disconnect arbitrarily.
Platform:
Further Analysis
socket.io@3
, but not insocket.io@2
, which works just fine.N=1e6
will disconnect, whileN=999000
will NOT disconnect.onClose
handler in./node_modules/engine.io-client/lib/transports/websocket.js
, you can debug the native WebSocket error event (which is inarguments[0]
).1005
.The text was updated successfully, but these errors were encountered: