Skip to content

Crash when using with fastify-http-proxy websockets #314

Open
@msundvick

Description

@msundvick

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.20.0

Plugin version

8.2.0

Node.js version

16.18.1

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

22.04

Description

Adding both a websocket endpoint and a proxy to a websocket endpoint doesn't work. Error seems mostly the same as fastify/fastify-websocket#249. If I switch around the order I add the proxy and websocket endpoint, I can get it to log the error and continue instead of just crashing, but still doesn't work.

Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

    at new NodeError (node:internal/errors:387:5)
    at assert (node:internal/assert:14:11)
    at ServerResponse.assignSocket (node:_http_server:280:3)
    at Server.<anonymous> (/home/msundvick/Documents/simulator/sgpsim/node_modules/@fastify/http-proxy/index.js:91:19)
    at Server.emit (node:events:525:35)
    at Server.emit (node:domain:489:12)
    at onParserExecuteCommon (node:_http_server:772:14)
    at onParserExecute (node:_http_server:686:3) {
  code: 'ERR_INTERNAL_ASSERTION'
}

Steps to Reproduce

  const proxy = await import("@fastify/http-proxy");
  if (backend) {
    await fastify.register(proxy, {
      upstream: backend,
      prefix: "/api", // optional
      http2: false, // optional
      websocket: true,
    });
  }

  await fastify.register(require("@fastify/websocket"));
  fastify.register(async function (fastify) {
    fastify.get("/api2", { websocket: true }, (connection, req) => {});
  });

Expected Behavior

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions