From 27d0eb054ce10e21c6daaeedf89fdd84a2855f5c Mon Sep 17 00:00:00 2001 From: cjihrig Date: Fri, 20 May 2016 19:10:48 -0400 Subject: [PATCH] child_process: emit IPC messages on next tick Currently, if an IPC event handler throws an error, it can cause the message to not be consumed, leading to messages piling up. This commit causes IPC events to be emitted on the next tick, allowing the channel's processing logic to move forward as normal. Fixes: https://github.com/nodejs/node/issues/6561 PR-URL: https://github.com/nodejs/node/pull/6909 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Santiago Gimeno --- lib/internal/child_process.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index ff26e8b75a..1ebfcd4c0c 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -715,7 +715,9 @@ function handleMessage(target, message, handle) { message.cmd.slice(0, INTERNAL_PREFIX.length) === INTERNAL_PREFIX) { eventName = 'internalMessage'; } - target.emit(eventName, message, handle); + process.nextTick(() => { + target.emit(eventName, message, handle); + }); } function nop() { }