oven-sh / bun

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

Running a script that uses interaction is super slow #9855

Open xixixao opened 5 months ago

xixixao commented 5 months ago

What version of Bun is running?

1.1.0

What platform is your computer?

Darwin 23.2.0 arm64 arm

What steps can reproduce the bug?

In a new directory, add file script.ts:

import { execSync } from "child_process";
execSync("npx convex init", { stdio: "inherit" });

Then run:

npm init
npm i convex
bun script.ts

Then run this again:

bun script.ts

You will get an interactive prompt from Convex.

What is the expected behavior?

Running the script through Bun should have no impact on the interactivity of the inner command.

What do you see instead?

The interactivity is super slow. This is not an issue when running the script.ts through Node.

Bun:

https://github.com/oven-sh/bun/assets/1473433/2a7d2d48-e6a8-461d-910b-bc55c8818126

Node:

https://github.com/oven-sh/bun/assets/1473433/ef724010-6798-4be2-afb2-bce7822ea37d

Additional information

Also quitting the nested command is super slow in Bun (but quick in Node).

davidgomes commented 2 months ago

I am seeing exactly the same thing in neonctl, but curiously I cannot reproduce with the repo from @xixixao. If I have this script.ts like @xixixao and then run $ bun script.ts, the interaction is fast:

import { execSync } from "child_process";
execSync("npx convex init", { stdio: "inherit" });

I am however, hitting this issue with this very similar line of code (npx vercel deploy):

https://github.com/neondatabase/neonctl/blob/6305ad6376f6655f648fe6e3694349bdaf1985ee/src/commands/bootstrap/index.ts#L637

One way to reproduce this is by doing brew install neonctl and then doing bun /opt/homebrew/bin/neonctl create-app. Once you get to the Vercel deployment step, the interaction becomes super slow. This doesn't happen with Node.


I have tried to create a minimum reproducible example but I simply can't. I tried the following, for example:

import { execSync } from "child_process";

function test() {
  execSync("command -v vercel", {
    cwd: "./src",
    stdio: "ignore",
  });

  execSync("npx vercel deploy", { stdio: "inherit" });

  execSync("rm -rf test-dir && mkdir test-dir", { stdio: "inherit" });

  execSync("npx vercel deploy", { stdio: "inherit", cwd: "test-dir" });
}

export const handler = async () => {
  await test();
};

handler();

But it just doesn't repro there. I have also tried to use Bun.spawnSync instead of execSync from child_process in neonctl, but the issue still happens.

This is all on Bun v1.1.18 (macOS arm64), Darwin Kernel Version 23.5.0.

davidgomes commented 2 months ago

I have managed to write a MRE (Minimum Reproducible Example):

Just run bun init, bun add prompts vercel and then bun index.ts:

const prompts = require("prompts");
const { execSync } = require("child_process");

async function handler() {
  const response = await prompts({
    type: "text",
    name: "name",
    message: "What is your name?",
  });

  execSync("npx vercel deploy", { stdio: "inherit" });
}

handler();

The Vercel CLI will be very slow, but not if you use Node.

If you comment out the await prompts call, then the issue doesn't happen.

davidgomes commented 2 months ago

@paperdave I read about how this is supposedly fixed in Bun v1.0.18, but I have managed to find a way to still hit it above.

davidgomes commented 2 months ago

I can confirm this is still happening on 1.1.20+ae1948925.

turbobuilt commented 1 month ago

Confirm still have this on 1.21.1

https://github.com/terkelg/prompts/issues/403

davidgomes commented 1 month ago

Can stil reproduce on 1.1.23.

nickcherry commented 1 month ago

Still happening for me with Expo EAS commands that involve interactive user input. I might be able to get a random character or two to appear, but CPU will spike and after hanging for 15-30 seconds, I'll manage to kill the process manually (ctrl+c).

Robinnnnn commented 1 month ago

Still happening for me with Expo EAS commands that involve interactive user input. I might be able to get a random character or two to appear, but CPU will spike and after hanging for 15-30 seconds, I'll manage to kill the process manually (ctrl+c).

seeing this exact issue as well

davidgomes commented 3 weeks ago

I can still reproduce on Bun 1.1.26.