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

Missing IPC chanel #501

Closed
arthot opened this issue Dec 25, 2017 · 3 comments
Closed

Missing IPC chanel #501

arthot opened this issue Dec 25, 2017 · 3 comments

Comments

@arthot
Copy link

arthot commented Dec 25, 2017

Hi, I've noticed yet another problem with a spawn of child process.
For now ts-node has the following option while creating a child node: stdio: 'inherit'.
And according node.js docs it means "no IPC" (Inter-process communication)

In reality this breaks a communication with yet another parent:

parent.js:

const cp = require('child_process');
cp.fork('child.ts', [], {
        env: process.env,
        execPath: 'node_modules/.bin/ts-node'
    });

child.ts:

if (!process.send)
    console.log('IPC is not enabled');
else
    console.log('IPC is enabled')

will produce IPC is not enabled

See more details in the sample repository with proper environment.

So I propose to replace the stdio option value with ['inherit', 'inherit', 'inherit', 'ipc'] in order to enable IPC. I think it's quite safe change because according the stdio doc

the child is launched with the IPC channel unreferenced until the child registers an event handler for the process

After such modification the sample will produce IPC is enabled

If someone is wondering about real-life use case sample:

  1. npm start
  2. webpack build client source
  3. run server api + webpack dev server
  4. wait until the server will start
  5. open browser

In this chain wait until the server will start is usually implemented in IPC way like process.send('online') and ts-node breaks this for now

PR #502

@arthot arthot mentioned this issue Dec 25, 2017
@blakeembrey
Copy link
Member

blakeembrey commented Dec 26, 2017

Thanks for the awesome writeup! I think I'll just kill child processes instead, the amount of hacks are becoming unmanageable and recommending node -r ts-node/register seems more ideal for advanced usage. Thanks!

@arthot
Copy link
Author

arthot commented Dec 26, 2017

Yep, if you have plans to remove child process in near future you can close this issue, because

cp.fork('child.ts', [], {
    env: process.env,
    execArgv: ['-r', 'ts-node/register']
});

also produces IPC is enabled

@blakeembrey
Copy link
Member

Closing with #536. Thanks for your patience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants