oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.44k stars 2.7k forks source link

Bun crashes when file is not available #11146

Closed agentquackyt closed 3 months ago

agentquackyt commented 4 months ago

How can we reproduce the crash?

Serving an not existing file

JavaScript/TypeScript code that reproduces the crash?

import { Logger } from "../../lib/logging";
import { Router } from "../../lib/route";
import { Config } from "../configuration/config";

let router_list: Router[] = [];

export let app = {
    use: (routes: Router) => {
        router_list.push(routes);
    }
}

const port = Config.server.port || 4000;
Logger.info("Starting server on port " + port);

export let server = Bun.serve({
    port: port,
    fetch(req: Request): Response | Promise<Response> | any {
        Logger.http(req);
        let url: string = new URL(req.url).pathname;
        for (let i = 0; i < router_list.length; i++) {
            const router = router_list[i];
            if(url.startsWith(router.getBaseRoute) || url.startsWith(router.getBaseRoute.slice(0, -1))) {
                let router_callback = router.run(req)
                if(router_callback != undefined) return router_callback;
            }
        }
        Logger.error("Fallback to default 404")
        return new Response(Bun.file("./frontend/views/404.html"), {status: 404});
    }
})

Relevant log output

PS Q:\UI Clones\html-css-projects\local-netflix\server> bun --hot index.ts
[info] Starting server on port 3000
GET http://localhost:3000/streams
GET http://localhost:3000/favicon.ico
ERROR: Fallback to default 404
============================================================
Bun v1.1.6 (e58d67b4) Windows x64
Args: "C:\Users\jonij\.bun\bin\bun.exe", "--hot", "index.ts"
Features: abort_signal http_server 
Builtins: "bun:main" 
Elapsed: 1925ms | User: 15ms | Sys: 0ms
RSS: 0.14GB | Peak: 0.14GB | Commit: 0.23GB | Faults: 33387

panic(main thread): Segmentation fault at address 0xFFFFFFFFFFFFFFFF
oh no: Bun has crashed. This indicates a bug in Bun, not your code.

To send a redacted crash report to Bun's team,
please file a GitHub issue using the link below:

Stack Trace (bun.report)

Bun v1.1.6 (e58d67b) on windows x86_64 [AutoCommand]

Segmentation fault at address 0xFFFFFFFFFFFFFFFF

Jarred-Sumner commented 3 months ago

Duplicate of #11617

Jarred-Sumner commented 3 months ago

We are tracking this in #11617, please follow along there.