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

WSS chromium works only after a first upgrade fail or connected with firefox first #11178

Open
m-valvano-zakeke opened this issue May 19, 2024 · 1 comment
Labels
bug Something isn't working bun.js Something to do with a Bun-specific API

Comments

@m-valvano-zakeke
Copy link

m-valvano-zakeke commented May 19, 2024

What version of Bun is running?

1.1.0

What platform is your computer?

Linux 5.10.0-28-cloud-amd64 x86_64 unknown

What steps can reproduce the bug?

When using Bun.serve to create a websocket server and you enable TLS, the server is not able to accept any request until you make a normal http request to let the upgrade fail or you use firefox first.

This is a normal bun serve from the example.
I have enable TLS with correct TLS and all the domains are correct (No CORS issues).

Bun.serve({
  port: 8080,
  fetch(req: any, server: any) {
    console.log("Fetch");
    if (server.upgrade(req)) {
      return; // do not return a Response
    }

    return new Response("Upgrade failed", { status: 500 });
  },
  tls: useSecure
    ? {
        cert: Bun.file(cert),
        key: Bun.file(key),
        ca: [Bun.file(chain)],
      }
    : null,
    ....

When running with no useSecure and you connect via ws:// protocol everything is ok.
But when you connect via wss:// protcol, the connection fail without any error and you are not able to see even the 'fetch' log.

BUT if you open chrome at wss://ip:port you will see, oblivusly, the "Upgrade failed" error.
From this time on, the websocket server works correctly and the applications is able to connect without issues.

The same is if you use FireFox, it just works on it and after the first connection also edge and chrome starts to work.

What is the expected behavior?

It should always connect correctly with all browsers the first time.

What do you see instead?

Connection failed on chrome and edge until you do a valid http request that fails the upgrade or you use firefox fist.

Additional information

No response

@m-valvano-zakeke m-valvano-zakeke added the bug Something isn't working label May 19, 2024
@m-valvano-zakeke m-valvano-zakeke changed the title WSS chromimu works only after a first upgrade fail or connected with firefox first WSS chromium works only after a first upgrade fail or connected with firefox first May 19, 2024
@Electroid
Copy link
Contributor

@cirospaciari Any ideas on this one?

@Electroid Electroid added the bun.js Something to do with a Bun-specific API label May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun.js Something to do with a Bun-specific API
Projects
None yet
Development

No branches or pull requests

2 participants