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

πŸ› Bug Report β€” Runtime APIs WebSocket can't connect to remote server when using custom port number #1751

Open
tien opened this issue Mar 1, 2024 · 1 comment

Comments

@tien
Copy link

tien commented Mar 1, 2024

Behaviour

When connecting to a remote web socket server running on a custom port. Cloudflare worker will try to use port 80/443 instead of the one specified in the URL, resulting in the following error if the url path doesn't exist on port 80/443:

Error: Uncaught TypeError: Failed to establish the WebSocket connection: expected server to reply with HTTP status code 101 (switching protocols), but received 404 instead.

This behaviour only happen with deployed worker, so if you run wrangler dev, local mode will work fine, but once you turn off local mode, the error will happen.

Reproduction steps

  • Create a server with a web socket application listening on port 8182 at path /my-path
  • Also add a normal web application on port 80 & 443 at path /, any other http(s) request to different path will return 404
  • Observe that new WebSocket('wss://thedomain.com:8182/my-path') work correctly everywhere, but fail on a deployed worker, throwing 404 not found
@tien
Copy link
Author

tien commented Mar 1, 2024

If I put the web socket application at port 80, 443 & 8182 then the socket connection to port 8182 work as expected. So it seems like Cloudflare worker will always go to the default port first and will error if the default port return 404, and then it will go to the port specified in the URL.

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

1 participant