node-dev icon indicating copy to clipboard operation
node-dev copied to clipboard

Flood of "Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed" errors

Open ianwalter opened this issue 8 years ago • 11 comments

Whenever I make a change to one of my files and node-dev says "Restarting", if I refresh my browser I get a flood of errors in my terminal that say:

Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed
    at process.target.send (internal/child_process.js:596:16)
    at Object.exports.send (/Users/ian/hq/app/node_modules/node-dev/lib/ipc.js:14:23)
    at process.<anonymous> (/Users/ian/hq/app/node_modules/node-dev/lib/wrap.js:45:7)
    at process.emit (events.js:127:13)
    at processEmit [as emit] (/Users/ian/ianwalter/fastify-vue/node_modules/signal-exit/index.js:155:32)
    at process._fatalException (bootstrap_node.js:434:26)

Does anyone have any clues on what I'm doing wrong? I'm running webpack-dev-middleware within my server and I'm wondering if I have to close it manually somehow?

❯ node -v v9.6.1

ianwalter avatar Apr 16 '18 01:04 ianwalter

Any news on this? We're (@danielesser) also running webpack-dev-middleware and explicitly call close on the middleware using the async-exit-hook module, like so:

exitHook(callback => middleware.close(callback));

Still, we're seeing the Error [ERR_IPC_DISCONNECTED]: IPC channel is already disconnected quite frequently (and thus have to restart our entire Docker dev. container).

qqilihq avatar Jun 13 '18 23:06 qqilihq

I would recommend switching to nodemon. Seems like this project is not maintained anymore.

johntran avatar Oct 07 '18 20:10 johntran

@johntran That's what we also did at the end (also, we got rid of the webpack-dev-middleware and replaced it by webpack via CLI). The combination of both (not sure which was the actual culprit) solved our issues.

qqilihq avatar Oct 07 '18 21:10 qqilihq

This should be fixed in v4.1.0

node-dev no longer tries to send messages to child processes that are disconnected.

bjornstar avatar Jul 02 '20 13:07 bjornstar

@bjornstar Good to hear, thanks for the update!

qqilihq avatar Jul 02 '20 14:07 qqilihq

Hi @bjornstar , I am using the latest available node-dev version (6.2.0) and I still get this issue a lot, and consistently.

I just do a quick repeat of "ctrl+s" on any file, inside an express application and I get a flood of those message (until the application get reloaded actually).

Also, looking at the code it seems that you are not checking for a disconnected child_process here: https://github.com/fgnass/node-dev/blob/57156cb094020f5c88409fff904ccca2f802d373/lib/ipc.js#L20

I added the condition here and no more "ERR_IPC_CHANNEL_CLOSED" errors.

But then still by doing a quick repeat on "ctrl +s" you can get an EPIPE error flood on this line: https://github.com/fgnass/node-dev/blob/57156cb094020f5c88409fff904ccca2f802d373/lib/ipc.js#L6

I guess the errors with the send comes from some race condition where the ipc is not valid anymore. And I guess this error is somehow causing the ipc calling again that cause a flood loop.

But anyway my question is why to show the errors anyway ? Having regularly a flood of these error messages on your console is just super annoying to the end-user (ie. the developper) and has zero value. Sometime the IPC is broken and I mean it's ok, as long as node-dev is not crashing your app there no need to see these errors (and it's not).

My suggestion which I think would improve a lot the user experience (at least mine:p) would be just to disable the logging of these errors, ie. to replace the send calls with something like:

dest.send(m, undefined, undefined, (err) => {})

I patched node-dev on my projects for some time with that and I have no issue so far, only a better ux. I would be glad to do a PR for that;)

Paul.

paeolo avatar Feb 18 '21 23:02 paeolo

I am using the latest available node-dev version (6.2.0) and I still get this issue a lot, and consistently.

I just do a quick repeat of "ctrl+s" on any file, inside an express application and I get a flood of those message (until the application get reloaded actually).

I am having trouble reproducing this issue, can you tell me more about your environment? Are you also using webpack-dev-middleware?

bjornstar avatar Feb 19 '21 03:02 bjornstar

Hi @bjornstar, I am not using webpack-dev-middleware and I am running Linux.

To make things easier for you to reproduce I set up a minimal case in this repository: https://github.com/paeolo/node-dev-ipc-errors.

The application being watched is the simplest express.js application you can think of and this example fork a child_process that spam a "CTRL+S" behavior every 100ms.

To test this, just clone the repository and then do a npm i followed by a npm run start. I successfully reproduced the errors with two different environments:

  • An up-to-date Archlinux environment (Linux 5.10.16-arch1-1, nodeJS v14.15.4)
  • An up-to-date Debian buster environment (Linux 4.19.0-14-cloud-amd64, nodeJS v14.15.5)

Note that the the aim of this repro is to reproduce an "write EPIPE" error on this line: https://github.com/fgnass/node-dev/blob/57156cb094020f5c88409fff904ccca2f802d373/lib/ipc.js#L6

But I can also reproduce an "ERR_IPC_CHANNEL_CLOSED" on this line: https://github.com/fgnass/node-dev/blob/57156cb094020f5c88409fff904ccca2f802d373/lib/ipc.js#L20 because in this line the check for dest.connected is missing.

Unfortunatly I really don't have the time to troubleshoot these issues myself, but I suggest at least to check for the dest.connected on the second send, and considering the fact that those error messages are useless to the user of node-dev, disabling the error messages by using something like

dest.send(m, err => {})

Best regards, Paul.

EDIT: sometime I can't reproduce it, i'll try to figure out the root of this and do a PR.

paeolo avatar Feb 19 '21 11:02 paeolo

@bjornstar I found the root of the issue, I am preparing a PR with some explanation.

paeolo avatar Feb 19 '21 15:02 paeolo

Hi @bjornstar, I am not using webpack-dev-middleware and I am running Linux.

To make things easier for you to reproduce I set up a minimal case in this repository: https://github.com/paeolo/node-dev-ipc-errors.

The application being watched is the simplest express.js application you can think of and this example fork a child_process that spam a "CTRL+S" behavior every 100ms.

To test this, just clone the repository and then do a npm i followed by a npm run start. I successfully reproduced the errors with two different environments:

  • An up-to-date Archlinux environment (Linux 5.10.16-arch1-1, nodeJS v14.15.4)
  • An up-to-date Debian buster environment (Linux 4.19.0-14-cloud-amd64, nodeJS v14.15.5)

@paeolo Thank you for putting up the reproduction repo, that was a huge help. I have released v6.3.0 which should resolve the issue.

bjornstar avatar Feb 22 '21 05:02 bjornstar

@bjornstar You're welcome, thank you to put time in it and to solve it. AFAIC it is solved.

paeolo avatar Feb 22 '21 16:02 paeolo