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

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

Closed
fisher60 opened this issue May 17, 2023 · 15 comments · Fixed by #18233
Closed
Labels
Area-Interop Communication between processes Help Wanted We encourage anyone to jump in on these. In-PR This issue has a related PR Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Repro We can't figure out how to make this happen. Please help find a simplified repro. Product-Terminal The new Windows Terminal.
Milestone

Comments

@fisher60
Copy link

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 fisher60 added Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels May 17, 2023
@fisher60
Copy link
Author

This issue seems very similar to #541

@zadjii-msft
Copy link
Member

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/?

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label May 17, 2023
@fisher60
Copy link
Author

This issue is still reproducible for me on preview version 1.17.1023

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels May 18, 2023
@carlos-zamora carlos-zamora added Help Wanted We encourage anyone to jump in on these. Area-Interop Communication between processes Needs-Repro We can't figure out how to make this happen. Please help find a simplified repro. Product-Terminal The new Windows Terminal. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Attention The core contributors need to come back around and look at this ASAP. labels May 31, 2023
@carlos-zamora carlos-zamora added this to the Backlog milestone May 31, 2023
@zadjii-msft zadjii-msft modified the milestones: Backlog, Terminal v1.19 Aug 2, 2023
@carlos-zamora
Copy link
Member

carlos-zamora commented Aug 2, 2023

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
Copy link

jsoldi commented Aug 4, 2023

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 zadjii-msft changed the title Exiting terminal while using panes does not terminate processes from terminal Exiting terminal while running npm in a pane does not terminate processes from terminal Aug 7, 2023
@zadjii-msft
Copy link
Member

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
Copy link

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
Copy link

Rusinas commented Feb 10, 2024

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
Copy link

jsoldi commented Feb 16, 2024

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
Copy link

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
Copy link

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
Copy link
Member

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!

@zadjii-msft zadjii-msft modified the milestones: Terminal v1.21, Backlog Sep 4, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Sep 4, 2024
@wesleyzloza
Copy link

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.

@microsoft-github-policy-service microsoft-github-policy-service bot added the No-Recent-Activity This issue/PR is going stale and may be auto-closed without further activity. label Sep 9, 2024
@lhecker lhecker removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Sep 9, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the No-Recent-Activity This issue/PR is going stale and may be auto-closed without further activity. label Sep 9, 2024
@jsoldi
Copy link

jsoldi commented Oct 12, 2024

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.

@Filyus
Copy link

Filyus commented Nov 19, 2024

Temporary solution for Windows:

taskkill /IM "node.exe" /F

Mac and Linux:

#!/bin/bash
pkill -f "node"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Interop Communication between processes Help Wanted We encourage anyone to jump in on these. In-PR This issue has a related PR Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Repro We can't figure out how to make this happen. Please help find a simplified repro. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging a pull request may close this issue.