tsx icon indicating copy to clipboard operation
tsx copied to clipboard

Improper handling of graceful exits

Open gz-95 opened this issue 2 years ago • 0 comments

Bug description

tsx does not wait for script to exit gracefully before terminating the process.

Reproduction

Let's say you have main.ts as the following:

console.log('starting up');

process.on('SIGINT', () => {
  console.log('shutting down');

  // simulate cleanup
  setTimeout(() => {
    console.log('cleanly exiting');
    process.exit(0);
  }, 5000);
});

// run forever
setInterval(() => {}, 1 << 30);

Running main.ts via node --no-warnings --loader tsx main.ts will produce the correct behavior, i.e. pressing CTRL+C will signal the script to start cleaning up and then exit gracefully.

On the other hand, when running via tsx main.ts, the process will exit abruptly when signaled without waiting for the script to completely finish cleaning up.

Environment

System:
    OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
    CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
    Memory: 10.00 GB / 15.52 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.7.0 - /usr/local/node/bin/node
    npm: 8.15.0 - /usr/local/node/bin/npm
  npmPackages:
    tsx: ^3.8.2 => 3.8.2

Can you contribute a fix?

  • [ ] I’m interested in opening a pull request for this issue.

gz-95 avatar Sep 02 '22 02:09 gz-95