oven-sh / bun

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

Bun crash when enable `pino-pretty` #11401

Open joeynq opened 2 months ago

joeynq commented 2 months ago

How can we reproduce the crash?

No response

JavaScript/TypeScript code that reproduces the crash?

Bun.serve({
  websocket: {
    message: (ws, data) => {
      const sid = uuid();
      return asyncLocalStorage.run({ sid }, {
        try {
          throw new Error("it crash after caught this");
        } catch (err) {
          ws.publish(err.message);
        }
      });
    }
  }
});

Relevant log output

Bun v1.1.10 (5102a944) Linux x64
Args: "bun" "src/index.ts"
Features: jsc Bun.stdin(2) bunfig dotenv(8) fetch http_server transpiler_cache(4) tsconfig(47)
Builtins: "bun:main" "bun:sqlite" "node:assert" "node:async_hooks" "node:buffer" "node:events" "node:fs" "node:module" "node:os" "node:path" "node:process" "node:stream" "node:string_decoder" "node:tty" "node:url" "node:util" "node:util/types" "node:worker_threads"
Elapsed: 150928ms | User: 1480ms | Sys: 1398ms
RSS: 0.69GB | Peak: 0.35GB | Commit: 0.69GB | Faults: 0

panic: Segmentation fault at address 0x6EA0
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:

 https://bun.report/1.1.10/la15102a94AqqihgF280ujE+xyQksllBA2Agq3B

Illegal instruction

Stack Trace (bun.report)

Bun v1.1.10 (5102a94) on linux x86_64 [AutoCommand]

Segmentation fault at address 0x00006EA0

Electroid commented 2 months ago

Could you share some code to reproduce this issue? It looks like the stack trace doesn't give us enough information.

joeynq commented 2 months ago

@Electroid I added example. I think the problem come from AsyncLocalStorage. ~When I remove als, it run without any crashes.~

It still crash when trying to send multiple message through websockets. more frequent with als enabled

joeynq commented 1 month ago

@Electroid I think I found the root cause. Turns out pino-pretty is the main problem.

The codes below only will throw panic: Segmentation fault at address 0x6EA0

const logger = pino({
  base: {},
    transport: {
      target: "pino-pretty", // disable this, the issue disappeared
      options: {
        crlf: true,
        translateTime: "SYS:HH:MM:ss.l",
        messageFormat: "{{traceId}} {msg}",
        ignore: "traceId,userIp,serverUrl,userAgent",
     },
  },
})
setInterval(() => {
  logger.info("Received message: %o", message);
}, 1000);
sirenkovladd commented 1 month ago
import { pino } from "pino";

const logger = pino({
  base: {},
  transport: {
    target: "pino-pretty", // disable this, the issue disappeared
    options: {
      crlf: true,
      translateTime: "SYS:HH:MM:ss.l",
      messageFormat: "{{traceId}} {msg}",
      ignore: "traceId,userIp,serverUrl,userAgent",
    },
  },
});
setInterval(() => {
  logger.info({ traceId: 123, test: 1 }, "Received message: %o", {
    version: Bun.version,
    revision: Bun.revision,
  });
}, 1000);
❯ bun run index.ts
[11:18:02.025] INFO: {123} Received message: {"version":"1.1.10","revision":"4b8f89cb73ac2b38f1da6a28eb91861eb7222264"}
    test: 1
[11:18:03.014] INFO: {123} Received message: {"version":"1.1.10","revision":"4b8f89cb73ac2b38f1da6a28eb91861eb7222264"}
    test: 1
[11:18:04.020] INFO: {123} Received message: {"version":"1.1.10","revision":"4b8f89cb73ac2b38f1da6a28eb91861eb7222264"}
    test: 1

Please, can you add more details?

joeynq commented 1 month ago

I'm running on:

And that's code crash after less than 30 seconds after started. Sometimes it crash after second or third log, sometimes it run longer. Just a very basic pino code as I posted. No more details.

I disabled pino-pretty and didn't experience any crash until now.