From 57dbc170e6d28fb9ec168ad9df94d2c78b1e553d Mon Sep 17 00:00:00 2001 From: Tom Udding Date: Wed, 13 Apr 2022 18:51:27 +0200 Subject: [PATCH] fix: Plugin error when sending on disconnected IPC channel (#21011) * fix: Plugin error when sending on disconnected IPC channel * Add unit test for new no send behaviour Co-authored-by: Emily Rohrbough --- packages/server/lib/plugins/util.js | 2 +- packages/server/test/unit/plugins/util_spec.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/server/lib/plugins/util.js b/packages/server/lib/plugins/util.js index 8d0e823847..b0b6e19076 100644 --- a/packages/server/lib/plugins/util.js +++ b/packages/server/lib/plugins/util.js @@ -25,7 +25,7 @@ module.exports = { return { send (event, ...args) { - if (aProcess.killed) { + if (aProcess.killed || !aProcess.connected) { return } diff --git a/packages/server/test/unit/plugins/util_spec.js b/packages/server/test/unit/plugins/util_spec.js index af64da26c5..0862675652 100644 --- a/packages/server/test/unit/plugins/util_spec.js +++ b/packages/server/test/unit/plugins/util_spec.js @@ -10,6 +10,7 @@ describe('lib/plugins/util', () => { this.theProcess = { send: sinon.spy(), on: sinon.stub(), + connected: true, } this.ipc = util.wrapIpc(this.theProcess) @@ -31,6 +32,13 @@ describe('lib/plugins/util', () => { expect(this.theProcess.send).not.to.be.called }) + it('#send does not send if process has been disconnected', function () { + this.theProcess.connected = false + this.ipc.send('event-name') + + expect(this.theProcess.send).not.to.be.called + }) + it('#on listens for process messages that match event', function () { const handler = sinon.spy()