zemse / hardhat-tracer

🕵️ allows you to see internal calls, events and storage operations in the console
MIT License
341 stars 35 forks source link

Bug: Spawned child process with hardhat-tracer does not exit #57

Open hwrdtm opened 1 year ago

hwrdtm commented 1 year ago

What

When I'm spawning a child process to run with the HRE, eg. npx hardhat run someRandomScript.ts, and with the hardhat-tracer imported in the hardhat.config.ts, I get a different behavior than without the tracer module imported. The different behavior is that, with the tracer imported, the child process does not exit.

Steps To Reproduce

  1. Create a file called someRandomScript.ts in a hardhat project:
// someRandomScript.ts
console.log("THIS");
  1. Run with npx hardhat run scripts/thing.ts
  2. Observe the script just hang.
  3. Comment out the console.log
  4. Run with the same command in step 2.
  5. Observe the script exit gracefully.

Versions

Platform

Macbook Pro 2021 Chip: Apple M1 Pro OS: macOS Ventura 13.3

zemse commented 11 months ago

This is a behaviour of nodejs when async tasks are not completed or get hanged. There are quite a lot of async tasks, I'll look into this issue which one gets hanged.

But if you are blocked by this problem, as a workaround you can add to the end of someRandomScript.ts:

// .. after your code runs:
process.exit() // this will stop the process ignoring any background pending async tasks if any