-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Do not patch the global child_process
module
#73
Comments
By thinking more about the use cases of This could be achieved with some light IPC between the root process and its descendants. |
I did some refactoring this week-end to reorganize the code from a single module to smaller chunks. It fixed some small issues, but especially allowed me to get a clear picture of how the module works by untangling some parts (especially the setup/shim creation from from the internals patching). Adding support for local wrappers should be possible soon. The only thing missing is to have mungers working on the The next feature is term of difficulty would be to run the main module and wrapper in their own processes. This would fix the issue where the wrapper's flags are leaking into the original main (for example Finally, the event-emitter based API is still a goal for me. This is the best API responding to the problem solved by this lib. It's also the hardest feature to implement. It will require to add some IPC (as mentioned) and a class acting as a ChildProcess proxy. The wrapper would spawn the original main and forward events and calls between the spawn process and the root. |
Hi,
I'm currently looking at providing a Node API for
c8
, a code coverage tool using V8's Profiler.The current code uses
spawn-wrap
. Sincespawn-wrap
modifies the globalchild_process
module, it is not safe to use it in a library: concurrent code trying to spawn processes will have unexpected results. This prevents running multiple coverages in parallel, or coverage and some other consumer tasks, inside the same Node process.The current workaround would be to run each instance of
c8
in its own process (independentchild_process
). This is very heavy-handed: it introduces friction and hurts composability. It means that the API must communicate with a subprocess so only serializable messages can be sent.I propose to do something similar to
graceful-fs@4
. The version3
modified the globalfs
module while version4
only returned a wrapper.Here is what the updated API would look like:
As stated in the example, this would introduce a breaking change but I believe that it would bring better behavior. The old behavior would still be accessible so transition would be easy.
The breaking change would also be the occasion to require Node 4+: there are other comments/issues mentioning problems with older Node versions. It would also simplify the current feature-detection mechanisms. This is not my main point though, I'm just proposing it by the way
What is needed is a way to spawn concurrent process-trees that do not interfere with each other, without isolating each root in its own sub-process.
Edit: /cc @bcoe @isaacs @sindresorhus
The text was updated successfully, but these errors were encountered: