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

Error: Invalid WebSocket frame: invalid UTF-8 sequence using Node 22.7 #2252

Closed
1 task done
st3ffgv4 opened this issue Aug 30, 2024 · 3 comments
Closed
1 task done

Comments

@st3ffgv4
Copy link

Is there an existing issue for this?

  • I've searched for any related issues and avoided creating a duplicate issue.

Description

Yesterday i've updated my client to nodejs 22.7.0 and it started to give this error after a while:

Error: Invalid WebSocket frame: invalid UTF-8 sequence
at Receiver.dataMessage (/root/b-core-mongo/node_modules/ws/lib/receiver.js:583:28)
at /root/b-core-mongo/node_modules/ws/lib/receiver.js:530:12
at /root/b-core-mongo/node_modules/ws/lib/permessage-deflate.js:309:9
at /root/b-core-mongo/node_modules/ws/lib/permessage-deflate.js:392:7
at afterWrite (node:internal/streams/writable:708:5)
at onwrite (node:internal/streams/writable:686:7)
at Zlib.cb (node:internal/streams/transform:191:7)
at Zlib.processCallback (node:zlib:632:8) {
code: 'WS_ERR_INVALID_UTF8',
[Symbol(status-code)]: 1007
}

My client configuration is

new WebSocket(
      `ws://${config.get("websocket.server.endpoint")}:${config.get(
        "websocket.server.port"
      )}`,
      {
        headers: {
          "x-bnode-name":
            process.env.BNODE_INSTANCE_NAME ?? os.hostname() ?? "test",
          "x-bnode-version": process.env.npm_package_version,
        },
      }
    );

My server configuration is:

new WebSocketServer({
      port: this.port,
      perMessageDeflate: {
        zlibDeflateOptions: {
          // See zlib defaults.
          chunkSize: 1024,
          memLevel: 7,
          level: 3,
        },
        zlibInflateOptions: {
          chunkSize: 10 * 1024,
        },
        // Other options settable:
        clientNoContextTakeover: true, // Defaults to negotiated value.
        serverNoContextTakeover: true, // Defaults to negotiated value.
        serverMaxWindowBits: 10, // Defaults to negotiated value.
        // Below options specified as default values.
        concurrencyLimit: 10, // Limits zlib concurrency for perf.
        threshold: 1024, // Size (in bytes) below which messages
        // should not be compressed if context takeover is disabled.
      },
    });

Bufferutil installed.
With node 22.6.0 all works well.
One thing that i can say is that i send lot of json strings.

ws version

8.18.0

Node.js Version

22.7.0

System

OS: Linux 6.8 Ubuntu 24.04.1 LTS 24.04.1 LTS (Noble Numbat)
CPU: (12) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
Memory: 12.68 GB / 15.28 GB
Container: Yes
Shell: 5.2.21 - /bin/bash

Expected result

no errors thrown

Actual result

Error: Invalid WebSocket frame: invalid UTF-8 sequence
at Receiver.dataMessage (/root/b-core-mongo/node_modules/ws/lib/receiver.js:583:28)
at /root/b-core-mongo/node_modules/ws/lib/receiver.js:530:12
at /root/b-core-mongo/node_modules/ws/lib/permessage-deflate.js:309:9
at /root/b-core-mongo/node_modules/ws/lib/permessage-deflate.js:392:7
at afterWrite (node:internal/streams/writable:708:5)
at onwrite (node:internal/streams/writable:686:7)
at Zlib.cb (node:internal/streams/transform:191:7)
at Zlib.processCallback (node:zlib:632:8) {
code: 'WS_ERR_INVALID_UTF8',
[Symbol(status-code)]: 1007
}

Attachments

No response

@lpinca
Copy link
Member

lpinca commented Aug 30, 2024

The error is self-explanatory. The peer is receiving invalid UTF-8 but it very unlikely to be a ws issue as nothing changed. See nodejs/node#54543.

@lpinca
Copy link
Member

lpinca commented Sep 5, 2024

This should be fixed in Node.js 22.8.0.

@lpinca lpinca closed this as completed Sep 5, 2024
@st3ffgv4
Copy link
Author

st3ffgv4 commented Sep 5, 2024

Yes fixed, thanks

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

No branches or pull requests

2 participants