oven-sh / bun

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

Bun error with read streams "panic: integer cast truncated bits" #10390

Closed lotrez closed 2 weeks ago

lotrez commented 5 months ago

What version of Bun is running?

1.1.4+fbe2fe0c3

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

I am trying to read a large csv sequentially via streams and csv-parser.

Here is the code:

import { createPinoLogger } from "@bogeychan/elysia-logger";
import { transform } from "csv";
import { parse } from "csv-parse";
import fs from "fs";

const log = createPinoLogger({
  level: "info",
  transport: {
    target: "pino-pretty",
    options: {
      colorize: true,
    },
  },
});

const parser = parse({
  delimiter: "  ",
  columns: true,
});

let headers = [];

const processRecord = transform((record, callback) => {
  log.info(record["code"]);
  callback(null, record);
});

async function main() {
  log.info("Starting readDump script...");
  if (!Bun.env.DUMP_PATH) throw new Error("DUMP_PATH is not defined");
  // create read stream of csv dumpfile
  const readStream = fs.createReadStream(Bun.env.DUMP_PATH);
  await new Promise((res, err) => {
    readStream
      .pipe(parser)
      .pipe(processRecord)
      .on("end", () => res);
  });
}

main().catch((e) => {
  log.error(e, e.name);
  process.exit(1);
});

What is the expected behavior?

It should keep running and read all lines in the csv file.

What do you see instead?

It crashes after a while with high RAM usage and disk reads.

bun run .\scripts\readDump.ts
[12:26:51.503] INFO (31196): Starting readDump script...
[12:26:51.517] INFO (31196): 00000000000000225
[12:26:51.518] INFO (31196): 0000000000000207025004
[12:26:51.518] INFO (31196): 00000000000003429145
[12:26:51.519] INFO (31196): 00000000000026772226
[12:26:51.519] INFO (31196): 0000000000017
[12:26:51.520] INFO (31196): 0000000000031
[12:26:51.521] INFO (31196): 000000000003327986
[12:26:51.522] INFO (31196): 000000000004128579
[12:26:51.522] INFO (31196): 000000000004622327
[12:26:51.523] INFO (31196): 000000000006021
[12:26:51.524] INFO (31196): 00000000001
[12:26:51.524] INFO (31196): 0000000000100
[12:26:51.524] INFO (31196): 0000000000123
[12:26:51.525] INFO (31196): 0000000000178
[12:26:51.525] INFO (31196): 0000000000208
[12:26:51.526] INFO (31196): 000000000025
[12:26:51.526] INFO (31196): 0000000000284

uh-oh: integer cast truncated bits
bun will crash now 😭😭😭

----- bun meta -----
Bun v1.1.4 (fbe2fe0c) Windows x64
RunCommand: tsconfig(8) dotenv(2) transpiler_cache
Builtins: "bun:main" "node:assert" "node:buffer" "node:events" "node:fs" "node:module" "node:os" "node:path" "node:stream" "node:string_decoder" "node:tty" "node:url" "node:util" "node:util/types" "node:worker_threads"
Elapsed: 27622ms | User: 2531ms | Sys: 2203ms
RSS: 10.31GB | Peak: 17.04GB | Commit: 10.41GB | Faults: 7452514
----- bun meta -----

0   00007FF6E64E2588
1   ???
2   ???
3   ???
4   ???
5   ???
6   ???
7   ???
8   ???
9   ???
10  ???
11  ???
12  ???
13  ???
14  ???

Search GitHub issues https://bun.sh/issues or join in #windows channel in https://bun.sh/discord

thread 12244 panic: integer cast truncated bits
???:?:?: 0x7ff6e5619397 in ??? (bun.exe)
???:?:?: 0x7ff6e5e0a717 in ??? (bun.exe)
???:?:?: 0x7ff6e5e0ee66 in ??? (bun.exe)
???:?:?: 0x7ff6e5e0e85f in ??? (bun.exe)
???:?:?: 0x7ff6e51bac11 in ??? (bun.exe)
???:?:?: 0x7ff6e761bd1a in ??? (bun.exe)
???:?:?: 0x7ff6e50e9010 in ??? (bun.exe)
???:?:?: 0x7ff6e50ec057 in ??? (bun.exe)
???:?:?: 0x7ff6e50ffbfc in ??? (bun.exe)
???:?:?: 0x7ff6e4e21603 in ??? (bun.exe)
???:?:?: 0x7ff6e79e4c63 in ??? (bun.exe)
???:?:?: 0x7ffe5cae257c in ??? (KERNEL32.DLL)
???:?:?: 0x7ffe5d78aa47 in ??? (ntdll.dll)

Additional information

No response

Jarred-Sumner commented 5 months ago

Can you run bun upgrade --canary and then report the crash using the crash reporter? That will give us a stack trace we can use.

lotrez commented 5 months ago

I am having the same issue as https://github.com/oven-sh/bun/issues/10078 when running bun upgrade --canary is there any way to get the canary version via the script?

Jarred-Sumner commented 5 months ago

I am having the same issue as #10078 when running bun upgrade --canary is there any way to get the canary version via the script?

Please try this:

irm bun.sh/install.ps1 -OutFile $env:TEMP\install.ps1; & $env:TEMP\install.ps1 -Version "canary"
lotrez commented 5 months ago

Thank you, here is the stack trace contained in the bun.report link.

Bun v1.1.5 (1a4bad8) on windows x86_64 [RunCommand]

panic: integer cast truncated bits

Features: dotenv, transpiler_cache, tsconfig

Jarred-Sumner commented 2 weeks ago

Pretty confident we fixed this error in Bun v1.1.20 or so