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

Cannot terminate whilst running imported function #45278

Closed
MauritsWilke opened this issue Nov 2, 2022 · 9 comments
Closed

Cannot terminate whilst running imported function #45278

MauritsWilke opened this issue Nov 2, 2022 · 9 comments
Labels
module Issues and PRs related to the module subsystem.

Comments

@MauritsWilke
Copy link

Version

v18.10.0

Platform

Linux Dennis 5.15.74-3-MANJARO #1 SMP PREEMPT Sat Oct 15 13:39:11 UTC 2022 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

  1. Create an index.js file that has an async function
  2. In said function, import a javascript file using await import()
  3. In the imported file have an async function that has a while(true) loop
  4. set a variable in the function to the imported function
  5. run index.js and try terminating whilst the while(true) loop is running (using ctrl+c)

Or use the repo where this occurs:

  1. Clone https://github.com/MauritsWilke/AdventOfCode
  2. Add a folder 22 under src/2015 and put in a part1.ts with the following code:
export default function solution(input:string) {
	while(true) {};
}
  1. Install the required modules and run tsc to compile (if it doesn´t happen automatically in VSC)
  2. Run node . and use the arrow keys to select the year 2015, the day 22 and the part 1

How often does it reproduce? Is there a required condition?

Every single time I run it on both the given platform and a windows platform

What is the expected behavior?

I expect ctrl+c to terminate the program.

What do you see instead?

Well nothing because it aint terminating :)

Additional information

No response

@Trott Trott added the module Issues and PRs related to the module subsystem. label Nov 2, 2022
@Trott
Copy link
Member

Trott commented Nov 2, 2022

@nodejs/modules

@ljharb
Copy link
Member

ljharb commented Nov 2, 2022

Does this happen without TLA, or without ESM, or does it require all of these conditions?

@MauritsWilke
Copy link
Author

I would have to set up some testing for that if it's really important

@ljharb
Copy link
Member

ljharb commented Nov 2, 2022

Narrowing down how broad the scope is seems important :-) that would be appreciated!

@MauritsWilke
Copy link
Author

Okay will do!

@MauritsWilke
Copy link
Author

I am failing to replicate this issue in a different folder. It might take some time for me to narrow down the issue

@MauritsWilke
Copy link
Author

I have not managed to narrow it down and am unable to repoduce it. If anyone wants to give it a shot be my guest but at this point i'm unsure if it has to do with NodeJS or a weird TypeScript error.

@GeoffreyBooth
Copy link
Member

Closing as unreproducible, if you have a minimum reproduction please comment and we can reopen.

@GeoffreyBooth GeoffreyBooth closed this as not planned Won't fix, can't repro, duplicate, stale Nov 3, 2022
@j4k0xb
Copy link

j4k0xb commented Nov 4, 2022

Here's a minimal reproduction that can't be terminated with ctrl+c (tested with the same OS, node 14, 16, 18):

process.on('SIGINT', () => process.exit(0));
while (true);

but these programs can be terminated:

while (true);
process.on('SIGINT', () => process.exit(0));
setTimeout(() => { }, 10_000);

inquirer used in @MauritsWilke's AdventOfCode example also set up a sigint handler.

Seems to be a duplicate issue: #9050

For anyone else who stumbles across this issue and wants a workaround: create a child process, worker_thread or fork that runs the sync/loop code. It can be terminated by the main process at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module Issues and PRs related to the module subsystem.
Projects
None yet
Development

No branches or pull requests

5 participants