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

Crash on latest beta #512

Closed
Nokel81 opened this issue Dec 7, 2021 · 10 comments · Fixed by #626
Closed

Crash on latest beta #512

Nokel81 opened this issue Dec 7, 2021 · 10 comments · Fixed by #626
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@Nokel81
Copy link

Nokel81 commented Dec 7, 2021

Environment details

  • OS: windows
  • OS version: 21H1 (19043.1348)
  • node-pty version: 0.11.0-beta11

Issue description

I was trying to debug an issue where if I kill a pty (that spawns powershell) within my electron app's main process while there is still input on (namely the last character sent was not \r or no characters were sent) then the whole application would freeze.

In doing so I tried to run the following code:

const pty = require("node-pty");

const shell = pty.spawn(process.env.PTYSHELL, [], {
    rows: 30,
    cols: 80,
    cwd: "C:\\",
    env: process.env,
    name: "xterm-256color",
});

shell.onExit((e) => {
    console.log(e); 
});

console.log("writing");
shell.write("a");
console.log("killing");
shell.kill();

console.log("killed");

and the output that I get is:

writing
killing
killed

events.js:377
      throw er; // Unhandled 'error' event
      ^
Error: read EPIPE
    at Pipe.onStreamRead (internal/stream_base_commons.js:209:20)
Emitted 'error' event on process instance at:
    at emitUnhandledRejectionOrErr (internal/event_target.js:578:11)
    at MessagePort.[nodejs.internal.kHybridDispatch] (internal/event_target.js:403:9)
    at MessagePort.exports.emitMessage (internal/per_context/messageport.js:18:26) {
  errno: -4047,
  code: 'EPIPE',
  syscall: 'read'
}

On beta10 I get the following:

writing
killing
killed
{ exitCode: 0, signal: undefined }

but then it hangs and does not exit.

This might be related to #471 but I thought that was supposed to be fixed in beta9

@Tyriar
Copy link
Member

Tyriar commented Dec 8, 2021

This sounds a lot like #375, can you verify the worker (_conoutSocketWorker) is getting spawned? conpty can hang the process if it's not drained in a worker

@Tyriar
Copy link
Member

Tyriar commented Dec 8, 2021

Also, I'd recommend spawning the pty on a different process, the electron main process is special and should be as free as possible.

@Nokel81
Copy link
Author

Nokel81 commented Dec 8, 2021

I got that crash running a normal node process node bug.js though, so I don't think that this is just about electron.

I will try to verify that it is being spawned

@Nokel81
Copy link
Author

Nokel81 commented Dec 8, 2021

So the _conoutSocketWorker.onReady() handler is being called.

@Nokel81
Copy link
Author

Nokel81 commented Dec 8, 2021

So I can also confirm that I am not seeing this bug if I set useConpty: false

@Tyriar
Copy link
Member

Tyriar commented Dec 16, 2021

This hang wasn't specific to Electron, but not connecting to conpty in its own thread as a deadlock could occur when input happens during exit. Still a little puzzled here as I thought it was fixed, and unfortunately build retention in ADO doesn't let me get the exact commit beta11 was based on.

@Nokel81
Copy link
Author

Nokel81 commented Dec 16, 2021

If it is necessary to spawn the connections on separate threads, should that be documented?

@Tyriar
Copy link
Member

Tyriar commented Dec 20, 2021

It's meant to be handled for you, I don't think there is a fallback. I guess you're just hitting some other problem that I've never seen 🤷

@LabhanshAgrawal
Copy link

@Tyriar I'm facing the same issue in Hyper, the first bad commit seems to be ba424e1

@Tyriar
Copy link
Member

Tyriar commented Jun 29, 2023

@rzhao271 FYI

@rzhao271 rzhao271 self-assigned this Jun 29, 2023
@rzhao271 rzhao271 added this to the July 2023 milestone Jun 29, 2023
@rzhao271 rzhao271 added the bug Issue identified by VS Code Team member as probable bug label Jun 29, 2023
@rzhao271 rzhao271 modified the milestones: July 2023, August 2023 Jul 21, 2023
@rzhao271 rzhao271 modified the milestones: August 2023, September 2023 Aug 25, 2023
ousttrue added a commit to ousttrue/xterm.mjs that referenced this issue Nov 5, 2023
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

Successfully merging a pull request may close this issue.

4 participants