Coder Social home page Coder Social logo

Kill child when exiting about execa HOT 9 CLOSED

sindresorhus avatar sindresorhus commented on June 22, 2024
Kill child when exiting

from execa.

Comments (9)

sindresorhus avatar sindresorhus commented on June 22, 2024

This is how the native childProcess.exec() works too. It would indeed be useful, but I don't really see how it would be possible to know what processes are executed as it's the shell that spawns them, not Node.js. Thoughts? I would suggest you instead use execa('ipfs', ['daemon']) both for performance and security reasons.

from execa.

dignifiedquire avatar dignifiedquire commented on June 22, 2024

This is how the native childProcess.exec() works too

Yes, sadly :( That's why I thought this might be a good place to improve on it :)

but I don't really see how it would be possible to know what processes are executed

What I currently do is keep track of the processes I spawn and attach handlers to exit and SIGINT on process to clean them up immediately before node.js exits. I totally understand if you think this is out of scope for this library but I wanted to mention as I can imagine me not being the only person needing this.
It probably would make sense to have this behind an option though rather than enabling it by default.

I would suggest you instead use execa('ipfs', ['daemon']) both for performance and security reasons.

The thing is that ipfs is not a node.js script but rather a binary out of my control.

from execa.

sindresorhus avatar sindresorhus commented on June 22, 2024

execa('ipfs', ['daemon']) works with any binary, not just Node.js.

from execa.

dignifiedquire avatar dignifiedquire commented on June 22, 2024

execa('ipfs', ['daemon']) works with any binary, not just Node.js.

Right..silly me. But I encounter the same issue with that, the process is spawned but not terminated when the parent exits.

from execa.

sindresorhus avatar sindresorhus commented on June 22, 2024

Hmm. I assumed Node.js would clean up direct child processes when exiting. Sounds like something it should do. Can you try opening an issue on Node.js first? And comment the link here. Would be better to try to fix it for everyone, not just this module. If they decline, we can add it here.

from execa.

dignifiedquire avatar dignifiedquire commented on June 22, 2024

Sure, I will do that later tonight

from execa.

dignifiedquire avatar dignifiedquire commented on June 22, 2024

Just filed an issue with a minimal example: nodejs/node#7951

from execa.

dignifiedquire avatar dignifiedquire commented on June 22, 2024

So as you can see from the issue this is the expected unixy behaviour. I still think it would be a great addition to optionally destroy the spawned process in this module. To catch that as referenced in the issue we could use https://www.npmjs.com/package/signal-exit.

Let me know if you are interested and I can work on a PR for adding this tracking behaviour.

from execa.

sindresorhus avatar sindresorhus commented on June 22, 2024

I'm not surprised. Unexpected behavior usually is expected UNIX behavior...

Sure, PR welcome :)

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.