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

Wrong pid on windows: Error: kill ESRCH #45

Closed
coderaiser opened this issue Mar 3, 2017 · 5 comments
Closed

Wrong pid on windows: Error: kill ESRCH #45

coderaiser opened this issue Mar 3, 2017 · 5 comments
Labels
bug Issue identified by VS Code Team member as probable bug
Milestone

Comments

@coderaiser
Copy link
Contributor

Every new started process gets wrong pid which is different from ones shown in task manager.
Could be reproduced with the demo of xterm.js.
Related to xterm.js issue.

> [email protected] start C:\Users\coderaiser\Documents\GitHub\xterm.js
> node demo/app

App listening to http://127.0.0.1:3000
Created terminal with PID: 928
Connected to terminal 928
internal/process.js:173
      throw errnoException(err, 'kill');
      ^

Error: kill ESRCH
    at exports._errnoException (util.js:1022:11)
    at process.kill (internal/process.js:173:13)
    at WebSocket.<anonymous> (C:\Users\coderaiser\Documents\GitHub\xterm.js\demo\app.js:72:13)
    at emitTwo (events.js:111:20)
    at WebSocket.emit (events.js:191:7)
    at WebSocket.cleanupWebsocketResources (C:\Users\coderaiser\Documents\GitHub\xterm.js\node_modules\ws\lib\WebSocket.js:950:8)
    at emitOne (events.js:101:20)
    at Socket.emit (events.js:188:7)
    at emitErrorNT (net.js:1281:8)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v7.2.0
npm ERR! npm  v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `node demo/app`
npm ERR! Exit status 1
@Tyriar
Copy link
Member

Tyriar commented Mar 3, 2017

This is also probably the root cause of microsoft/vscode#14286

It's related to winpty, currently it's being set to (int)winpty_agent_process(pc) here, which points at the winpty agent process. Perhaps the handle is not being cast correctly?

@Tyriar
Copy link
Member

Tyriar commented Mar 3, 2017

@rprichard is there an easy way to get the winpty agent process ID from winpty_agent_process? I see it being set here but not sure if this is surfaced through the API?

@rprichard
Copy link
Contributor

Yes, you'd call GetProcessId on the winpty_agent_process handle. Don't close the agent process handle afterwards -- libwinpty does that itself.

Do you want the PID of the winpty agent or the PID of the process running inside winpty (e.g. powershell.exe)? If you want the latter, then you need to get a process handle from winpty_spawn and pass that to GetProcessId.

The code is currently getting the spawned child process' handle and putting it into handle:

HANDLE handle = nullptr;
BOOL spawnSuccess = winpty_spawn(pc, config, &handle, nullptr, nullptr, nullptr);

The code doesn't do anything with handle, though. It doesn't even close the handle, so the handle is leaked (until the node process exits). (The PID is also leaked and can't be reused until the node process exits).

I'd guess you actually want to use GetProcessId(handle), then call CloseHandle on the spawned handle when the pty object is cleaned up.

Alternatively, if you really do want the agent PID, then you can fix the handle leak by passing nullptr to winpty_spawn:

BOOL spawnSuccess = winpty_spawn(pc, config, nullptr, nullptr, nullptr, nullptr);

@Tyriar
Copy link
Member

Tyriar commented Mar 4, 2017

Thanks @rprichard, I do want the inner process from winpty_spawn (powershell).

@Tyriar Tyriar added this to the 0.6.3 milestone Mar 4, 2017
@Tyriar Tyriar added the bug Issue identified by VS Code Team member as probable bug label Mar 4, 2017
@Tyriar
Copy link
Member

Tyriar commented Mar 12, 2017

Managed to get this working pretty easily thanks to your help @rprichard 👍

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

3 participants