Skip to content

Missing IPC chanel #501

Closed
Closed
@arthot

Description

@arthot

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions