From cf4ea94e6ddbaab0eb2b94edbae64759f860eb95 Mon Sep 17 00:00:00 2001 From: Ben Lubar Date: Fri, 28 Sep 2018 16:02:03 -0500 Subject: [PATCH] Fix single-host-cluster socket.io (#6802) It was silently dropping every message because every node thought it was the master node. --- src/socket.io/index.js | 4 +--- src/socket.io/single-host-cluster.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/socket.io/index.js b/src/socket.io/index.js index 964ebf728c..4c772db131 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -28,9 +28,7 @@ Sockets.init = function (server) { }); if (nconf.get('singleHostCluster')) { - io.adapter(require('socket.io-adapter-cluster')({ - client: require('./single-host-cluster'), - })); + io.adapter(require('./single-host-cluster')); } else if (nconf.get('redis')) { io.adapter(require('../database/redis').socketAdapter()); } else { diff --git a/src/socket.io/single-host-cluster.js b/src/socket.io/single-host-cluster.js index c7ca938766..eef1a7a4a7 100644 --- a/src/socket.io/single-host-cluster.js +++ b/src/socket.io/single-host-cluster.js @@ -51,4 +51,17 @@ process.on('message', function (message) { } }); -module.exports = Client; +var adapter = require('socket.io-adapter-cluster')({ + client: Client, +}); +// Otherwise, every node thinks it is the master node and ignores messages +// because they are from "itself". +Object.defineProperty(adapter.prototype, 'id', { + get: function () { + return process.pid; + }, + set: function (id) { + // ignore + }, +}); +module.exports = adapter;