Coder Social home page Coder Social logo

Comments (10)

sindresorhus avatar sindresorhus commented on September 23, 2024 1

I also got confused between those two properties while checking this issue. Should we rename execaError.killed to avoid that confusion? For example execaError.aborted, execaError.terminated, or anything else?

Yes. I prefer using is or was prefix for the property.

from execa.

SamVerschueren avatar SamVerschueren commented on September 23, 2024

I was looking into implementing this but I need some help first. In the spawned.on('exit') handler I wanted to set spawned.killed to true if the signal indicates that it was killed. But what signals indicate a kill? Or can we check it in a different way?

I was now checking for SIGTERM and SIGINT but don't think that's enough.

from execa.

okonet avatar okonet commented on September 23, 2024

@SamVerschueren I think https://github.com/Tapppi/async-exit-hook/blob/master/index.js#L89-L94 is a good enough list

from execa.

ehmicky avatar ehmicky commented on September 23, 2024

I've opened an issue with Node.js to make childProcess.killed true even when the child process was killed through process.kill() or kill in the terminal (as opposed to childProcess.kill()).

from execa.

bnoordhuis avatar bnoordhuis commented on September 23, 2024

But what signals indicate a kill?

If signal != null in proc.on('exit', (code, signal) => { /* ... */ }), then that's the signal that terminated the process.

If your question is "how do I determine whether it's sent by kill(2)", the answer is "you don't." :-)

from execa.

ehmicky avatar ehmicky commented on September 23, 2024

Yes I think @bnoordhuis fix for it (checking signal on exit) is the correct one. However I still think that providing this as part of Node.js might be a good idea (as opposed to execa).

from execa.

ehmicky avatar ehmicky commented on September 23, 2024

From the discussion at nodejs/node#27490, it appears childProcess.killed just means "childProcess.kill() was called". Regardless of whether it terminated the process. For example childProcess.kill(0) sets childProcess.killed as true. The purpose of childProcess.killed seems to be mostly about idempotency, e.g. preventing calling childProcess.kill() multiple times.

Instead, that discussion highlights that the best way to check this is to look at the signal that is passed as a second argument to the exit event of the child process.

In other words, we might want to replace:

error.killed = killed && !timedOut;

By:

error.killed = error.signal !== undefined;

The documentation says:

signal The signal by which the child process was terminated.

So, we can assume that if a signal is passed, it was the one that terminated the child process.

What do you think?

from execa.

sindresorhus avatar sindresorhus commented on September 23, 2024

👍

We should document that it differs from the one in Node.js.

from execa.

ehmicky avatar ehmicky commented on September 23, 2024

There is actually a difference between:

  • childProcess.killed: left as is by Execa, i.e. has the same behavior as core Node.js. It only checks whether childProcess.kill() has been called (even .kill(0)), to prevent from calling it several times.
  • execaError.killed: intended to check whether the child process was "killed", i.e. terminated by a signal. At the moment, it does not behave as such. Instead it behaves like childProcess.killed, which can probably be considered a bug.

I.e. since execaError.killed is an Execa addition, we do not differ from Node.js behavior.

I also got confused between those two properties while checking this issue. Should we rename execaError.killed to avoid that confusion? For example execaError.aborted, execaError.terminated, or anything else?

from execa.

ehmicky avatar ehmicky commented on September 23, 2024

Sounds good. Done at #625.

from execa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.