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

Inquirer.js search prompt hangs the console on Ctrl+C #17636

Open
Atulin opened this issue Feb 24, 2025 · 1 comment
Open

Inquirer.js search prompt hangs the console on Ctrl+C #17636

Atulin opened this issue Feb 24, 2025 · 1 comment
Labels
bug Something isn't working confirmed bug We can reproduce this issue node:process

Comments

@Atulin
Copy link

Atulin commented Feb 24, 2025

What version of Bun is running?

1.2.2+c1708ea6a

What platform is your computer?

Microsoft Windows NT 10.0.26100.0 x64

What steps can reproduce the bug?

The exact code I used to reproduce the issue is as follows:

import { search } from "@inquirer/prompts";
import Fuse from "fuse.js";
import { readdirSync } from "node:fs";
import { basename } from "node:path";

export const selectSpec = async (args: { spec: string }) => {
	if (args.spec.length > 0) {
		return args.spec;
	}

	const specs = readdirSync("specs");
	const fuse = new Fuse(specs, {});

	return await search({
		message: "Select a spec",
		source: (input) => {
			if (!input) {
				return [];
			}

			const results = fuse.search(input).map((result) => basename(result.item));
			return results.map((spec) => ({
				name: spec,
				value: spec,
			}));
		},
	}).catch(() => {
		process.exit(0);
	});
};

await selectSpec({ spec: "" });

Running it with Node via npx tsx test.ts, entering a search query, and pressing Ctrl+C terminates the application as usual.

Running it with Bun via bun test.ts, entering a search query, and pressing Ctrl+C renders the console unresponsive and does not terminate the application.

What is the expected behavior?

Pressing Ctrl+C when running the code with Bun works

What do you see instead?

Pressing Ctrl+C when running the code with Bun renders the terminal unresponsive to input

Code_eJKx3V92sC.mp4

Additional information

PowerShell 7.5.0

@pfgithub
Copy link
Contributor

pfgithub commented Feb 25, 2025

Inquirer depending on tapjs/signal-exit which is overwriting process.emit :(

https://github.com/tapjs/signal-exit/blob/d8621bc82431d9a6c4b9c4f17dc08b2b137fbb48/src/index.ts#L247

Issue 1 (this is why it doesn't throw an error that would cause the promise to fail and then cause the process to exit)

// repro.js
import * as readline from "readline";

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
rl.question("abc", () => {});

process.emit = (ev, arg) => {
    if (ev !== "exit") return;
    console.log("got exit event", arg);
};
$> node repro
^C
got exit event 0

$> bun repro
^C

$>

Issue 2 (this is why it hangs despite there being nothing to do)

// repro2.js
await new Promise(r => {});
$> node repro2
Warning: Detected unsettled top-level await at file:///Users/pfg/Dev/Node/temp/generated/b9c2ab6210fe10190b6ed03a0f1d585a/tmp/a.js:1
await new Promise(r => {});
^
Exited with code [13]

$> bun repro2
... hangs

Issue 3

On windows it stops accepting any input & ctrl+c doesn't work. On mac, pressing ctrl+c twice will kill the process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed bug We can reproduce this issue node:process
Projects
None yet
Development

No branches or pull requests

2 participants