#Secure WebSockets (WSS) not working?

1 messages · Page 1 of 1 (latest)

fleet chasm
#

I've been trying to test out WebSockets with a secure server and it doesnt work so great.

Is there something I'm missing or is WSS broken currently in v0.4.0?

import { serve, } from "bun";

serve({
  port: 3000,
  keyFile: "./localhost.key",
  certFile: "./localhost.pem",
  websocket: {
    message(ws, msg) {
      ws.send('sup dawg?');
    },
  },
  fetch(req, server) {
    if (
      req.url.endsWith('/chat') &&
      server.upgrade(req)
    ) {
      return new Response("", {
        status: 101,
      });
    }

    console.log(
      "fetch",
      req,
    );

    return new Response(
      `
        <!DOCTYPE html>
        <html>
        <head>
          <meta charset="utf-8">
          <title>WebSockets</title>
        </head>
        <body>
          <style></style>
          <script>
            const ws = new WebSocket("wss://localhost:3000/chat");
            ws.onopen = (e) => {
              ws.send("ping");
            };
            ws.onmessage = (e) => {
              console.log('ws msg', e)
            };
          </script>
          <div id="app">
            <h1>bun --hot ./index.js</h1>
          </div>
        </body>
        </html>
      `,
      {
        headers: {
          "Content-Type": "text/html; charset=utf-8",
        },
      },
    );
  },
});

Tried that with bun run index.js and bun --hot index.js. It goes boom with both.

[1]    183168 segmentation fault (core dumped)  bun run index.js
WebSocket connection to 'wss://localhost:3000/chat' failed:

I've tried various combinations and it seems to work with the keyFile & certFile disabled but not with them enabled.

the localhost certs were generated with https://github.com/FiloSottile/mkcert

Work fine with just HTTPS so far as I can tell, just not when websockets are added in.

GitHub

A simple zero-config tool to make locally trusted development certificates with any names you'd like. - GitHub - FiloSottile/mkcert: A simple zero-config tool to make locally trusted develo...

mortal kernel
#

hm

#

and then

#

assuming that crashes again

#

if you're on macOS, can you go to Console.app

#

and paste the crash report

#

i'm able to repro

#

oh

#

i see the bug

#

I have a fix

mortal kernel
#

fix is pushed, when canary finishes building please run bun upgrade --canary and retry

fleet chasm
fleet chasm
fleet chasm
#

Do I need to do more than bun-profile --hot index.js or bun-profile run index.js?

Both just seem to show a similar segfault, does that drop stuff in the system logs or something?

mortal kernel
#

if you're on macOS x64

#

the build hasn't finished

#

oh

#

pop_os

#

3 minutes ago

#

@fleet chasm please try upgrading again, it only just finished on linux

fleet chasm
#

You rock dude!