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

The script under the system user continues to run after closing the terminal. #94877

Closed
KostyaTretyak opened this issue Apr 10, 2020 · 12 comments
Assignees
Labels
*as-designed Described behavior is as designed terminal General terminal issues that don't fall under another label

Comments

@KostyaTretyak
Copy link

KostyaTretyak commented Apr 10, 2020

  • VSCode Version: 1.44.0
  • OS Version: Linux x64 5.3.0-46-generic

Steps to Reproduce:

1. create index.js script for node server:

const http = require('http');

const server = http.createServer((req, res) => {
  res.end('OK');
});

server.listen(8080, () => {
  console.log('server work on http://localhost:8080');
});

2. in VS Code integrated terminal, login under system user, in my case it's node-user:

sudo -u node-user -Hs

3. run the script:

node index.js

4. from second terminal, check work:

curl -isS localhost:8080

response:

HTTP/1.1 200 OK
Date: Fri, 10 Apr 2020 07:37:15 GMT
Connection: keep-alive
Content-Length: 2

OK

5. kill first integrated terminal or close VS Code
6. check work and the script continues to work:

curl -isS localhost:8080

response:

HTTP/1.1 200 OK
Date: Fri, 10 Apr 2020 07:37:15 GMT
Connection: keep-alive
Content-Length: 2

OK

P.S. To kill the process, run:

sudo kill -9 `sudo lsof -t -i:8080`
@Tyriar Tyriar added bug Issue identified by VS Code Team member as probable bug terminal General terminal issues that don't fall under another label upstream Issue identified as 'upstream' component related (exists outside of VS Code) labels Apr 10, 2020
@Tyriar Tyriar added this to the Backlog milestone Apr 10, 2020
@meganrogge meganrogge added *not-reproducible Issue cannot be reproduced by VS Code Team member as described and removed confirmation-pending labels Oct 12, 2021
@meganrogge meganrogge reopened this Oct 12, 2021
@meganrogge meganrogge removed the *not-reproducible Issue cannot be reproduced by VS Code Team member as described label Oct 12, 2021
@microsoft microsoft deleted a comment Oct 12, 2021
@meganrogge
Copy link
Contributor

I can reproduce the issue you're seeing when I run this first

sudo -u <my-username> -Hs

@meganrogge
Copy link
Contributor

Not sure what -H does but this happens also if you just run sudo -u <my-username> -s IE when logged in, killing the terminal doesn't kill the process

@meganrogge meganrogge added the confirmed Issue has been confirmed by VS Code Team member label Oct 12, 2021
@meganrogge
Copy link
Contributor

meganrogge commented Oct 12, 2021

here are the logs when I kill the terminal with the context menu action:

TRACE CommandService#executeCommand workbench.action.terminal.killInstance
workbench.desktop.main.js:601 TRACE terminalInstance#dispose (instanceId: 3)
workbench.desktop.main.js:601 DEBUG Terminal process exit (instanceId: 3) with code undefined
workbench.desktop.main.js:601 DEBUG Terminal process exit (instanceId: 3) state 5
workbench.desktop.main.js:601 TRACE terminalInstance#dispose (instanceId: 3)

state 5 just indicates killed by user

@meganrogge
Copy link
Contributor

I believe this is an upstream node-pty issue

@meganrogge
Copy link
Contributor

microsoft/node-pty#437

@meganrogge meganrogge added the upstream-issue-linked This is an upstream issue that has been reported upstream label Oct 12, 2021
@jerch
Copy link

jerch commented Oct 12, 2021

Thats actually expected behavior. The culprit behind is the sudo move - the POSIX permissions system is meant to disallow any process manipulations from an under privileged account, thus closing the PTY cannot clean sudo'ed child processes via SIGHUP.

@meganrogge meganrogge added *as-designed Described behavior is as designed and removed bug Issue identified by VS Code Team member as probable bug upstream Issue identified as 'upstream' component related (exists outside of VS Code) confirmed Issue has been confirmed by VS Code Team member upstream-issue-linked This is an upstream issue that has been reported upstream labels Oct 12, 2021
@meganrogge meganrogge removed this from the Backlog milestone Oct 12, 2021
@KostyaTretyak
Copy link
Author

@jerch, if this is the expected behavior, then why doesn't it happen when we work, for example, with the default terminal for Ubuntu 20.04?

@jerch
Copy link

jerch commented Oct 13, 2021

@KostyaTretyak I cannot tell you that. But have a few hints/remarks for that issue: In principle there are two ways to tear down a child process tree behind a PTY - first send the session leader (first program on the pty) SIGHUP by yourself. That signal will bubble through the children (if the session leader cooperates), but cannot pass the user permission border, as it was created by the user of the pty process. Thus the kernel wont deliver it to sudo'ed processes. A second more robust way is to let the kernel create that signal in the first place, e.g. by simply closing the PTY master end. That second method has one big advantage - it can cross user permission borders, since it comes from the kernel itself (who is allowed to do anything anyway).

So my guess is - vscode prolly uses method 1, while your default ubuntu terminal uses method 2 (or even both of them)?

@KostyaTretyak
Copy link
Author

No, I think it's true bug, and it was not worth closing this issue.

@jerch
Copy link

jerch commented Oct 13, 2021

Tried to give you an explanation to your "why..." question. In that context your "No, I think it's true bug" makes absolutely no sense without any further explanation from your side. Geez, why do I even care to explain things...

@KostyaTretyak
Copy link
Author

@jerch, your explanation did not seem logical to me.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*as-designed Described behavior is as designed terminal General terminal issues that don't fall under another label
Projects
None yet
Development

No branches or pull requests

5 participants
@Tyriar @KostyaTretyak @jerch @meganrogge and others