Skip to content

Allow attaching multiple WebSocket proxies #258

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

Merged
merged 1 commit into from
Jun 29, 2022
Merged

Allow attaching multiple WebSocket proxies #258

merged 1 commit into from
Jun 29, 2022

Conversation

yoursunny
Copy link
Contributor

Previously, if multiple WebSockets-enabled proxies are added to the same fastify.Server instance at distinct URI prefixes, the program crashes with error:

/app/node_modules/.pnpm/[email protected]/node_modules/ws/lib/websocket-server.js:363
      throw new Error(
      ^

Error: server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration
    at WebSocketServer.completeUpgrade (/app/node_modules/.pnpm/[email protected]/node_modules/ws/lib/websocket-server.js:363:13)
    at WebSocketServer.handleUpgrade (/app/node_modules/.pnpm/[email protected]/node_modules/ws/lib/websocket-server.js:339:10)
    at Server.upgrade (/app/node_modules/.pnpm/[email protected]/node_modules/ws/lib/websocket-server.js:114:16)
    at Server.emit (node:events:539:35)
    at onParserExecuteCommon (node:_http_server:732:14)
    at onParserExecute (node:_http_server:646:3)
 ELIFECYCLE  Command failed with exit code 1.

This PR fixes this problem by only attaching one WebSocket.Server to the same HTTP server, and then internally dispatches WebSocket connections to different upstreams via longest prefix match lookup among registered prefixes.

Checklist

@mcollina mcollina merged commit af293f3 into fastify:master Jun 29, 2022
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

Successfully merging this pull request may close these issues.

2 participants