oven-sh / bun

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

Does not behave the same as nodejs when using pg-copy-streams and pipeline #10273

Open palforsberg opened 7 months ago

palforsberg commented 7 months ago

What version of Bun is running?

1.1.3+2615dc742

What platform is your computer?

Darwin 23.4.0 arm64 arm

What steps can reproduce the bug?

Create a postgres database with some database table fix.event_log Run this script in both nodejs and bun. Nodejs finishes as expected, bun gets stuck on pipeline.

import pg from "pg";
import { to as copyTo } from "pg-copy-streams";
import { pipeline } from "node:stream/promises";
import fs from "fs";
const { Client } = pg;

const tables = [
  { table: "fix.event_log" },
];
const dir = "./data"
if (!fs.existsSync(dir)){
    fs.mkdirSync(dir, { recursive: true });
}

const client = new Client({
  connectionString: "postgresql://postgres:password@localhost:8000/postgres",
});

await client.connect();
for (const t of tables) {
    const csvFilePath = `${dir}/${t.table}.csv`;
    const writableStream = fs.createWriteStream(csvFilePath);
    const stream = client.query(copyTo(`COPY (SELECT * FROM ${t.table}) TO STDOUT WITH CSV HEADER`));
    console.log("start pipeline")
    await pipeline(stream, writableStream);
    console.log("end pipeline")
}
console.log("Data exported");

await client.end()

and package.json

{
  "name": "export_db",
  "module": "index.js",
  "type": "module",
  "dependencies": {
    "minimist": "^1.2.8",
    "pg": "^8.11.5",
    "pg-copy-streams": "^6.0.6"
  }
}

What is the expected behavior?

Same behavior for both nodejs and bun

What do you see instead?

 await pipeline(stream, writableStream);

never finishes in bun

Additional information

Im not sure if there's a better way to utilize Bun's file I/O to better write to the file. I've tried different approaches but haven't gotten any to work.

github-actions[bot] commented 3 months ago

This issue is stale and may be closed due to inactivity. If you're still running into this, please leave a comment.