microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
95.76k stars 8.33k forks source link

Exiting terminal while running `npm` in a pane does not terminate processes from terminal #15373

Open fisher60 opened 1 year ago

fisher60 commented 1 year ago

Windows Terminal version

1.16.10261.0

Windows build number

10.0.19045.0

Other Software

Node.js v16.14.2

Steps to reproduce

  1. Open Windows Terminal
  2. Split panes
  3. Start a process in one pane (I was using npm run start to run a local website with React)
  4. Observe website running in web browser
  5. Use the x button on the windows terminal window to exit windows terminal
  6. Background process is still running and website is still working in web browser

Expected Behavior

When quitting windows terminal, background processes should be stopped. The local server running the React website should also be terminated when windows terminal exits.

Actual Behavior

Background process continues running indefinitely. Task manager does not indicate any windows terminal tasks running in the background. The background task appears to be buried and is difficult to discover so the easiest way to terminate the process is to restart the machine. Restarting the machine terminates the background process and website is no longer hosted.

fisher60 commented 1 year ago

This issue seems very similar to #541

zadjii-msft commented 1 year ago

Pretty confident that this isn't #541 - that was a specific bug from like, almost 4 years ago now.

If anything, I'd think that #14544 would have helped here. Can you try this with Terminal Preview (v1.17), and see if that fixes this/?

fisher60 commented 1 year ago

This issue is still reproducible for me on preview version 1.17.1023

carlos-zamora commented 1 year ago

Repro steps from #15708

  1. Create a folder and clone my sample repro: npx degit https://github.com/jsoldi/windows-terminal-bug. It's just a plain server that does nothing.
  2. Do npm install
  3. Open the Windows Terminal on the project folder and run npm start 3000 and then visit localhost:3000 on a browser.
  4. Close the terminal.
  5. Reload localhost:3000 and the server should still be running

If the process actually stops, try repeating steps 3-5 one more time.

jsoldi commented 1 year ago

I think it's important to highlight that this only seems to occur with npm projects. The process will actually stop either if I run the script directly with node index.js, or if I do npm start from CMD or PS, so somehow the combination of terminal and npm seems to cause the issue.

zadjii-msft commented 1 year ago

Another repro:

1.17.11461.0, 10.0.19044.3086, node v18.15.0

Steps to reproduce

  1. open terminal
  2. split pane (shift+alt+-)
  3. run node (npm run dev)
  4. close terminal (alt+f4 or X button)
AdamLeMmon01 commented 9 months ago

If I run npm in a PS command, I observe this same behavior: wt new-tab pwsh -c "& {npm run start}"

If I run npm in a PS job, the background job is terminated correctly when I close the pane/tab/window wt new-tab pwsh -c "& {Start-Job {npm run start}}"

Rusinas commented 9 months ago

Same here with the PS command. I was debugging a ps1 script and noticed that each time I run it the port number increments. Then I had to go to the task manager and manually kill 20+ node processes... .__. This is weird.

jsoldi commented 9 months ago

Why is this bug not getting more attention? It makes the terminal completely useless for anything other than very specific toy projects and people unaware of the bug will get their system resources slowly eaten up until things start failing.

Jimmaphy commented 9 months ago

Tried to recreate the bug with different methods. As both #15708 and #15801 mentioned, running the provided repo through node directly doesn't trigger the behavior. Using yarn, instead of npm, also doesn't trigger this behavior.

luidera22 commented 8 months ago

This bug is kind of scary, to be honest. I started a project and then when I thought the server was closed it was still running (after 7h that I first closed the terminal). I checked everything and found nothing. But then the last shot was looking into the Process Explorer and bang: node.js still running initialized by command line npm start.

zadjii-msft commented 2 months ago

Hey can anyone check if this still repros on 1.22 Preview/? We did some improvements to the way we generate CTRL_CLOSE events over the last couple of releases, and we're pretty confident we're doing it right now. Thanks!

wesleyzloza commented 2 months ago

I am still experiencing this issue on the 1.22 preview (specifically v1.22.2362.0). In my case I am running a local server for a Angular website. The development server will persist after the terminal is exited.

jsoldi commented 1 month ago

This is still happening on preview version 1.22.2702.0. To replicate just run npm run start from the terminal, where package.json contains "scripts": { "start": "node ./index.js" } and index.js is:

// index.js
import express from 'express';

const app = express();
const port = 3000;
app.get('/', (req, res) => { res.send('Hello World'); });
app.listen(port, () => { console.log(`Server is running at http://localhost:${port}`); });

Then close the terminal and the server will still be running.