bun icon indicating copy to clipboard operation
bun copied to clipboard

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

Open m-valvano-zakeke opened this issue 1 year ago • 1 comments
trafficstars

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 avatar May 19 '24 16:05 m-valvano-zakeke

@cirospaciari Any ideas on this one?

Electroid avatar May 20 '24 16:05 Electroid