From 0b8124f205723d197ea2f0fd93e566234abbac09 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 f482d85a2c84d3..3613bfd0efeec8 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -692,7 +692,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() { }