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

Random crash when hitting multiple threads hard #17206

Open
tatarmb4s opened this issue Feb 9, 2025 · 1 comment
Open

Random crash when hitting multiple threads hard #17206

tatarmb4s opened this issue Feb 9, 2025 · 1 comment
Labels
crash An issue that could cause a crash linux An issue that occurs on Linux

Comments

@tatarmb4s
Copy link

How can we reproduce the crash?

Just run the default multithreading example:

cluster.ts

import { spawn } from "bun";

const cpus = navigator.hardwareConcurrency; // Number of CPU cores
const workers = new Array(cpus);
// const workers = new Array(16);

for (let i = 0; i < cpus; i++) {
    workers[i] = spawn({
        cmd: ["bun", "./src/index.ts"],
        stdout: "inherit",
        stderr: "inherit",
        stdin: "inherit"
    });
}

function kill() {
    for (const worker of workers) {
        worker.kill();
    }
}

process.on("SIGINT", kill);
process.on("exit", kill);

console.log(`Started ${cpus} worker processes`);

index.ts

import { PrismaClient } from "@prisma/client";
import { RequestRecievedEvent, Route } from "./system/requestHandler";

export const prisma = new PrismaClient();
export const PORT = process.env.PORT || "3000";

const workerId = Math.random().toString(36).slice(2);

const server = Bun.serve({
    port: Number(PORT),
    reusePort: true, // Enable port sharing between processes

    fetch(request, server) {
        return RequestRecievedEvent(request);
    }
});

await import("./routes");
console.log(`Worker ${workerId} started on ${server.hostname}:${server.port}`);

Hit the API endpoint as hard as possible from multiple threads and it will happen randomly.

OS: Debian 12
bun --version: 1.1.45

Relevant log output

Forgot to copy it before console clear but it was Memory adress error and Its a bun error please report it text.

Stack Trace (bun.report)

Bun v1.1.42 (50eec00) on linux x86_64 [AutoCommand]

Segmentation fault at address 0x00000000

  • ??
  • ??
  • ??
  • ??
  • ??
  • ??
  • ??
  • ??
  • ??
  • ??

Features: process_dlopen, dotenv, fetch, http_server, jsc, transpiler_cache, tsconfig, tsconfig

@tatarmb4s tatarmb4s added the crash An issue that could cause a crash label Feb 9, 2025
@github-actions github-actions bot added the linux An issue that occurs on Linux label Feb 9, 2025
Copy link
Contributor

github-actions bot commented Feb 9, 2025

@tatarmb4s, thank you for reporting this crash. The latest version of Bun is v1.2.2, but this crash was reported on Bun v1.1.42.

Are you able to reproduce this crash on the latest version of Bun?

bun upgrade

For Bun's internal tracking, this issue is BUN-22K.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash An issue that could cause a crash linux An issue that occurs on Linux
Projects
None yet
Development

No branches or pull requests

1 participant