uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
7.76k stars 563 forks source link

maxPayloadLength is being ignored #949

Closed tayler-king closed 11 months ago

tayler-king commented 1 year ago

For some reason it seems as though maxPayloadLength is being ignored. See the following code which is a essentially an echo server:

import uWebSockets from 'uWebSockets.js';
const app = new uWebSockets.App();

app.ws('/', {
    maxPayloadLength: 32 * 1024 * 1024, // example of raised limits
    maxBackpressure: 32 * 1024 * 1024,
    idleTimeout: 0,

    upgrade: (res, req, context) => {
        res.upgrade(
            { subscriber: decodeURIComponent(req.getHeader('sec-websocket-protocol')) },
            req.getHeader('sec-websocket-key'),
            req.getHeader('sec-websocket-protocol'),
            req.getHeader('sec-websocket-extensions'),
            context,
        );
    },

    open: socket => {
        socket.subscribe(socket.subscriber);
    },

    message: (socket, message) => {
        app.publish(socket.subscriber, message);
    },
}).listen(7039);

If a client sends a message that is 16 * 1024 bytes it works without issue, if it sends a message 16 * 1024 + 1 bytes then the connection is closed.. Am I just being stupid? I'm using the ws library as the client with a maxPayload of 100MiB.

Interestingly it doesn't call the close handler (not pictured above) when this happens..

uNetworkingAB commented 1 year ago

Please provide a minimal reproducer.

tayler-king commented 1 year ago

@uNetworkingAB I have created a reproducer available at https://github.com/tayler-king/uWS-maximum-payload

$ node server.js
SERVER: started socket server on port 7032
$ node client.js
CLIENT: established connection to socket server
CLIENT: received message from socket server with length 128
CLIENT: received message from socket server with length 16384
CLIENT: lost connection to socket server 1006
e3dio commented 11 months ago

I tried to reproduce this using the same settings, different combo of settings, publishing the message, both web browser and ws client library, not able to reproduce issue at all, maxPayloadLength working correctly at 32 1024 1024

e3dio commented 11 months ago

I tried your example repo, works fine

CLIENT: established connection to socket server CLIENT: received message from socket server with length 128 CLIENT: received message from socket server with length 16384 CLIENT: received message from socket server with length 32768

tayler-king commented 11 months ago

I tried to reproduce this using the same settings, different combo of settings, publishing the message, both web browser and ws client library, not able to reproduce issue at all, maxPayloadLength working correctly at 32 1024 1024

Let me validate that I was running this on the latest version and get back to you.

e3dio commented 11 months ago

What system are you running on, I use Amazon Linux 2023 Arm64. I used latest uWS.js 20.31.0 and Node.js 20.5.1

tayler-king commented 11 months ago

What system are you running on, I use Amazon Linux 2023 Arm64. I used latest uWS.js 20.31.0 and Node.js 20.5.1

Apple M2. Will update once I've double checked the package and node version.

tayler-king commented 11 months ago

I haven't been able to replicate again. Yarn must've cached an older version - latest version doesn't have this issue.