node.jsvisual-studio-code

Is there a way to tell Visual Studio Code to kill integrated terminal processes gracefully?


My Node.js script does some cleanup on exit by catching various signals or the process.on('exit', ...) event.

When I run this script in a vscode integrated terminal and close or reload the editor or use the "Kill Terminal" button, well, it kills the terminal and the cleanup portion of the script is not executed.

Current workaround (not ideal): manually send Ctrl+C to terminals.


Solution

  • "Maybe" this new setting in vscode v101 might help:

    Gracefully shutdown terminal and task processes

    We’ve added an opt-in setting, setting(terminal.integrated.killGracefully), to cleanly shut down terminal processes, including child processes. This helps avoid orphaned processes, frees up ports, and can reduce the risk of resource leaks.

    Terminal > Integrated: Kill Gracefully in your Settings.

    from v101 vnext Release Notes