diff --git a/index.js b/index.js index e1e94e7d..c5b200ba 100644 --- a/index.js +++ b/index.js @@ -44,6 +44,7 @@ var SocketCluster = function (options) { self.EVENT_WORKER_CLUSTER_EXIT = 'workerClusterExit'; self._pendingResponseHandlers = {}; + self.workerClusterMessageBuffer = []; self._errorAnnotations = { 'EADDRINUSE': 'Failed to bind to a port because it was already used by another process.' @@ -125,6 +126,7 @@ SocketCluster.prototype._init = function (options) { self._active = false; self.workerCluster = null; + self.isWorkerClusterReady = false; self._colorCodes = { red: 31, @@ -388,9 +390,11 @@ SocketCluster.prototype._logObject = function (obj, objType, time) { SocketCluster.prototype._convertValueToUnknownError = function (err, origin) { if (err && typeof err == 'object') { - // If err has neither a stack or message property - // then the error message will be the JSON stringified object. - if (!err.message && !err.stack) { + if (err.message || err.stack) { + err = scErrors.hydrateError(err, true); + } else { + // If err has neither a stack nor a message property + // then the error message will be the JSON stringified object. var errorMessage; try { errorMessage = JSON.stringify(err); @@ -489,6 +493,8 @@ SocketCluster.prototype._workerWarningHandler = function (workerPid, warning) { SocketCluster.prototype._workerClusterReadyHandler = function () { var self = this; + this.isWorkerClusterReady = true; + if (!this._active) { if (this.options.rebootOnSignal) { process.on('SIGUSR2', function () { @@ -512,6 +518,8 @@ SocketCluster.prototype._workerClusterReadyHandler = function () { this._logDeploymentDetails(); } + this._flushWorkerClusterMessageBuffer(); + var workerClusterInfo = { pid: this.workerCluster.pid, childProcess: this.workerCluster @@ -538,6 +546,8 @@ SocketCluster.prototype._workerStartHandler = function (workerInfo, signal) { }; SocketCluster.prototype._handleWorkerClusterExit = function (errorCode, signal) { + this.isWorkerClusterReady = false; + var workerClusterInfo = { pid: this.workerCluster.pid, code: errorCode, @@ -591,6 +601,7 @@ SocketCluster.prototype._launchWorkerCluster = function () { } this.workerCluster = fork(__dirname + '/lib/workercluster.js', process.argv.slice(2), execOptions); + this.isWorkerClusterReady = false; var workerOpts = this._cloneObject(this.options); workerOpts.paths = this._paths; @@ -631,7 +642,7 @@ SocketCluster.prototype._launchWorkerCluster = function () { self._workerClusterErrorHandler(m.data.pid, m.data.error); } } else if (m.type == 'warning') { - var warning = scErrors.hydrateError(m.data.error); + var warning = scErrors.hydrateError(m.data.error, true); self._workerWarningHandler(m.data.workerPid, warning); } else if (m.type == 'ready') { self._workerClusterReadyHandler(); @@ -640,17 +651,18 @@ SocketCluster.prototype._launchWorkerCluster = function () { } else if (m.type == 'workerExit') { self._workerExitHandler(m.data); } else if (m.type == 'workerMessage') { - self.emit('workerMessage', m.workerId, m.data, function (data) { + self.emit('workerMessage', m.workerId, m.data, function (err, data) { if (m.cid) { - self.respondToWorker(data, m.workerId, m.cid); + self.respondToWorker(err, data, m.workerId, m.cid); } }); - } else if (m.type == 'workerResponse') { + } else if (m.type == 'workerResponse' || m.type == 'workerClusterResponse') { var responseHandler = self._pendingResponseHandlers[m.rid]; if (responseHandler) { clearTimeout(responseHandler.timeout); delete self._pendingResponseHandlers[m.rid]; - responseHandler.callback(null, m.data, m.workerId); + var properError = scErrors.hydrateError(m.error, true); + responseHandler.callback(properError, m.data, m.workerId); } } }); @@ -662,11 +674,15 @@ SocketCluster.prototype._launchWorkerCluster = function () { this.emit(this.EVENT_WORKER_CLUSTER_START, workerClusterInfo); this.workerCluster.on('exit', this._handleWorkerClusterExit.bind(this)); + this.workerCluster.on('disconnect', function () { + self.isWorkerClusterReady = false; + }); }; -SocketCluster.prototype.respondToWorker = function (data, workerId, rid) { +SocketCluster.prototype.respondToWorker = function (err, data, workerId, rid) { this.workerCluster.send({ type: 'masterResponse', + error: scErrors.dehydrateError(err, true), data: data, rid: rid }); @@ -727,6 +743,7 @@ SocketCluster.prototype._start = function () { expiryAccuracy: self._dataExpiryAccuracy, downgradeToUser: self.options.downgradeToUser, processTermTimeout: self.options.processTermTimeout, + ipcAckTimeout: self.options.ipcAckTimeout, brokerOptions: self.options, appBrokerControllerPath: self._paths.appBrokerControllerPath, appInitControllerPath: self._paths.appInitControllerPath @@ -750,8 +767,8 @@ SocketCluster.prototype._start = function () { self.emit(self.EVENT_BROKER_EXIT, brokerInfo); }); - self._brokerEngineServer.on('brokerMessage', function (brokerId, data) { - self.emit('brokerMessage', brokerId, data); + self._brokerEngineServer.on('brokerMessage', function (brokerId, data, callback) { + self.emit('brokerMessage', brokerId, data, callback); }); }; @@ -759,6 +776,7 @@ SocketCluster.prototype._start = function () { }; SocketCluster.prototype._createIPCResponseHandler = function (callback) { + var self = this; var cid = uuid.v4(); var responseTimeout = setTimeout(function () { @@ -776,6 +794,15 @@ SocketCluster.prototype._createIPCResponseHandler = function (callback) { return cid; }; +SocketCluster.prototype._flushWorkerClusterMessageBuffer = function () { + var self = this; + + this.workerClusterMessageBuffer.forEach(function (messagePacket) { + self.workerCluster.send(messagePacket); + }); + this.workerClusterMessageBuffer = []; +}; + SocketCluster.prototype.sendToWorker = function (workerId, data, callback) { var self = this; @@ -788,11 +815,15 @@ SocketCluster.prototype.sendToWorker = function (workerId, data, callback) { if (callback) { messagePacket.cid = this._createIPCResponseHandler(callback); } - this.workerCluster.send(messagePacket); + this.workerClusterMessageBuffer.push(messagePacket); + + if (this.isWorkerClusterReady) { + this._flushWorkerClusterMessageBuffer(); + } }; SocketCluster.prototype.sendToBroker = function (brokerId, data, callback) { - this._brokerEngineServer.sendToBroker(brokerId, data); + this._brokerEngineServer.sendToBroker(brokerId, data, callback); }; // The options object is optional and can have two boolean fields: diff --git a/kubernetes/socketcluster-deployment.yaml b/kubernetes/socketcluster-deployment.yaml index 6a23f22f..ab7a48d2 100644 --- a/kubernetes/socketcluster-deployment.yaml +++ b/kubernetes/socketcluster-deployment.yaml @@ -11,7 +11,7 @@ spec: spec: containers: - name: socketcluster - image: socketcluster/socketcluster:v6.5.0 + image: socketcluster/socketcluster:v6.6.0 ports: - containerPort: 8000 env: diff --git a/lib/scworker.js b/lib/scworker.js index 7f1bf431..c382c13a 100644 --- a/lib/scworker.js +++ b/lib/scworker.js @@ -349,6 +349,7 @@ SCWorker.prototype.getStatus = function () { }; SCWorker.prototype._createIPCResponseHandler = function (callback) { + var self = this; var cid = uuid.v4(); var responseTimeout = setTimeout(function () { @@ -371,7 +372,8 @@ SCWorker.prototype.handleMasterResponse = function (message) { if (responseHandler) { clearTimeout(responseHandler.timeout); delete this._pendingResponseHandlers[message.rid]; - responseHandler.callback(null, message.data); + var properError = scErrors.hydrateError(message.error, true); + responseHandler.callback(properError, message.data); } }; @@ -388,9 +390,10 @@ SCWorker.prototype.sendToMaster = function (data, callback) { process.send(messagePacket); }; -SCWorker.prototype.respondToMaster = function (data, rid) { +SCWorker.prototype.respondToMaster = function (err, data, rid) { process.send({ type: 'workerResponse', + error: scErrors.dehydrateError(err, true), data: data, workerId: this.id, rid: rid @@ -404,9 +407,9 @@ SCWorker.prototype.handleMasterEvent = function () { SCWorker.prototype.handleMasterMessage = function (message) { var self = this - self.emit('masterMessage', message.data, function (data) { + self.emit('masterMessage', message.data, function (err, data) { if (message.cid) { - self.respondToMaster(data, message.cid); + self.respondToMaster(err, data, message.cid); } }); }; diff --git a/lib/workercluster.js b/lib/workercluster.js index 57ebd50a..7ccd4367 100644 --- a/lib/workercluster.js +++ b/lib/workercluster.js @@ -123,6 +123,16 @@ if (cluster.isMaster) { ' because the worker does not exist'; var notFoundError = new InvalidActionError(errorMessage); sendErrorToMaster(notFoundError); + + if (m.cid) { + process.send({ + type: 'workerClusterResponse', + error: scErrors.dehydrateError(notFoundError, true), + data: null, + workerId: m.workerId, + rid: m.cid + }); + } } } else { if (m.type == 'terminate' && m.data.killClusterMaster) { diff --git a/package-lock.json b/package-lock.json index 7ecfa41a..e235d614 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "socketcluster", - "version": "6.5.0", + "version": "6.6.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -423,24 +423,32 @@ } }, "sc-broker": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/sc-broker/-/sc-broker-3.0.0.tgz", - "integrity": "sha1-o0SRgWvcKq9vI1YslC65UF61R30=", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/sc-broker/-/sc-broker-3.1.0.tgz", + "integrity": "sha512-eWr7cYYqHc7HVC+MHK9NRqYbQmfDEjcO881cYEGpMjk9U69h8G+f+hgJsKib4ZvXFWYMp8slWyqenvQPudIVgQ==", "requires": { "expirymanager": "0.9.3", "fleximap": "0.9.10", "ncom": "0.11.1", "sc-domain": "1.0.1", - "sc-errors": "1.3.3" + "sc-errors": "1.3.3", + "uuid": "3.1.0" + }, + "dependencies": { + "uuid": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", + "integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==" + } } }, "sc-broker-cluster": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/sc-broker-cluster/-/sc-broker-cluster-4.0.3.tgz", - "integrity": "sha1-WcA7McOW30QQ5tGYulDsB0BQjw8=", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/sc-broker-cluster/-/sc-broker-cluster-4.1.0.tgz", + "integrity": "sha512-ekNge91lhSm5GpBjUsSFybSgvh0E0fVlHurqZYIrc1jBqWc2z8zBRsaJujRx7ly1RdoC+t6DY8kRrihGNt2eSg==", "requires": { "async": "2.0.0", - "sc-broker": "3.0.0", + "sc-broker": "3.1.0", "sc-channel": "1.0.6", "sc-domain": "1.0.1", "sc-errors": "1.3.3", diff --git a/package.json b/package.json index 614e5002..8a7383fa 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "socketcluster", "description": "SocketCluster - A Highly parallelized WebSocket server cluster to make the most of multi-core machines/instances.", - "version": "6.5.0", + "version": "6.6.0", "homepage": "http://socketcluster.io", "contributors": [ { @@ -13,10 +13,6 @@ "type": "git", "url": "git://github.com/SocketCluster/socketcluster.git" }, - "scripts":{ - "test":"npm run test::masterToWorkerCallback", - "test::masterToWorkerCallback":"node test/internal/serverToWorker.js" - }, "dependencies": { "async": "2.0.0", "base64id": "0.1.0", @@ -24,7 +20,7 @@ "inquirer": "1.1.3", "minimist": "1.1.0", "sc-auth": "~4.1.1", - "sc-broker-cluster": "~4.0.3", + "sc-broker-cluster": "~4.1.0", "sc-domain": "~1.0.1", "sc-emitter": "~1.1.0", "sc-errors": "~1.3.3", diff --git a/sample/package.json b/sample/package.json index 06c6b883..df94b6ce 100644 --- a/sample/package.json +++ b/sample/package.json @@ -18,7 +18,7 @@ "sc-hot-reboot": "~1.0.0", "scc-broker-client": "~1.4.0", "serve-static": "1.11.2", - "socketcluster": "~6.5.0", + "socketcluster": "~6.6.0", "socketcluster-client": "~6.3.0" }, "keywords": [ diff --git a/test/internal/broker.js b/test/internal/broker.js index ed94d1df..72ef06bc 100644 --- a/test/internal/broker.js +++ b/test/internal/broker.js @@ -1,6 +1,6 @@ var fs = require('fs'); var http = require('http'); -var getTestSocketPath = require('./testsocketpath').getTestSocketPath; +var getTestSocketPath = require('./test-socket-path').getTestSocketPath; var util = require('util'); module.exports.run = function (broker) { diff --git a/test/internal/broker2.js b/test/internal/broker2.js new file mode 100644 index 00000000..82f6983c --- /dev/null +++ b/test/internal/broker2.js @@ -0,0 +1,51 @@ + +module.exports.run = function (broker) { + console.log(' >> Broker PID:', process.pid); + + broker.on('masterMessage', function (data, res) { + console.log(`BROKER ${broker.id}::Received data from master:`, data); + if (data.fail) { + var err = new Error('This is an error from broker'); + err.name = 'MyCustomBrokerError'; + res(err); + } else if (!data.doNothing) { + res(null, { + id: 1, + name: 'TestName' + }); + } + }); + + var packet = { + prop: 1234 + }; + + console.log(`BROKER ${broker.id}::Sending packet to master`); + broker.sendToMaster(packet, function (err, data) { + console.log(`BROKER ${broker.id}::Response error from master:`, err); + console.log(`BROKER ${broker.id}::Response data packet from master:`, data); + }); + + var timeoutPacket = { + doNothing: true + }; + + console.log(`BROKER ${broker.id}::Sending timeout-causing packet to master`); + broker.sendToMaster(timeoutPacket, function (err, data) { + console.log(`BROKER ${broker.id}::Timeout response error from master:`, err); + console.log(`BROKER ${broker.id}::Timeout response data packet from master:`, data); + }); + + var errorPacket = { + fail: true + }; + + console.log(`BROKER ${broker.id}::Sending error-causing packet to master`); + broker.sendToMaster(errorPacket, function (err, data) { + console.log(`BROKER ${broker.id}::Error response error from master:`, err); + console.log(`BROKER ${broker.id}::Error response data packet from master:`, data); + }); + + console.log(`BROKER ${broker.id}::Sending error-causing packet to master without callback`); + broker.sendToMaster(errorPacket); +}; diff --git a/test/internal/index.js b/test/internal/index.js index 0619209c..3679b395 100644 --- a/test/internal/index.js +++ b/test/internal/index.js @@ -5,7 +5,7 @@ var assert = require('assert'); var http = require('http'); var util = require('util'); var fs = require('fs'); -var getTestSocketPath = require('./testsocketpath').getTestSocketPath; +var getTestSocketPath = require('./test-socket-path').getTestSocketPath; var scServer = childProcess.fork(__dirname + '/server.js'); var resultSocketPath = getTestSocketPath(); diff --git a/test/internal/master-to-broker.js b/test/internal/master-to-broker.js new file mode 100644 index 00000000..af26b9cf --- /dev/null +++ b/test/internal/master-to-broker.js @@ -0,0 +1,76 @@ +var SocketCluster = require('../../index').SocketCluster; + +var socketCluster = new SocketCluster({ + workers: 2, + brokers: 2, + port: 8000, + appName: 'myapp', + workerController: __dirname + '/worker2.js', + brokerController: __dirname + '/broker2.js', + socketChannelLimit: 100, + crashWorkerOnError: true, + rebootWorkerOnCrash: true, + ipcAckTimeout: 1000 +}); + +socketCluster.on('brokerMessage', function (brokerId, data, respond) { + console.log(`MASTER::Received data from broker ${brokerId}:`, data); + if (data.fail) { + var err = new Error('Failure from master'); + err.name = 'MasterFailureError'; + respond(err); + } else if (!data.doNothing) { + respond(null, { + qwerty: 123456 + }); + } +}); + +var packet = { + id: 0, + name: 'SocketCluster' +}; + +console.log('MASTER::Sending packet to broker 0'); +socketCluster.sendToBroker(0, packet, function (err, data) { + console.log('MASTER::Response error from broker 0:', err); + console.log('MASTER::Response data from broker 0:', data); +}); + +console.log('MASTER::Sending packet to broker 1'); +socketCluster.sendToBroker(1, packet, function (err, data) { + console.log('MASTER::Response error from broker 1:', err); + console.log('MASTER::Response data from broker 1:', data); +}); + +console.log('MASTER::Sending packet to non-existent broker 2'); +socketCluster.sendToBroker(2, packet, function (err, data) { + console.log('MASTER::Response error from non-existent broker 2:', err); + console.log('MASTER::Response data from non-existent broker 2:', data); +}); + +var errorPacket = { + fail: true +}; + +console.log('MASTER::Sending error-causing packet to broker 0'); +socketCluster.sendToBroker(0, errorPacket, function (err, data) { + console.log('MASTER::Error response error from broker 0:', err); + console.log('MASTER::Error response data from broker 0:', data); +}); + +console.log('MASTER::Sending error-causing packet to broker without callback 0'); +socketCluster.sendToBroker(0, errorPacket); + +var timeoutPacket = { + doNothing: true +}; + +console.log('MASTER::Sending timeout-causing packet to broker 0'); +socketCluster.sendToBroker(0, timeoutPacket, function (err, data) { + console.log('MASTER::Timeout response error from broker 0:', err); + console.log('MASTER::Timeout response data from broker 0:', data); +}); + +console.log('MASTER::Sending timeout-causing packet to broker 0 without callback'); +socketCluster.sendToBroker(0, timeoutPacket); diff --git a/test/internal/master-to-worker.js b/test/internal/master-to-worker.js new file mode 100644 index 00000000..eb34eb69 --- /dev/null +++ b/test/internal/master-to-worker.js @@ -0,0 +1,76 @@ +var SocketCluster = require('../../index').SocketCluster; + +var socketCluster = new SocketCluster({ + workers: 2, + brokers: 2, + port: 8000, + appName: 'myapp', + workerController: __dirname + '/worker.js', + socketChannelLimit: 100, + crashWorkerOnError: true, + rebootWorkerOnCrash: true, + ipcAckTimeout: 1000 +}); + +socketCluster.on('workerMessage', function (workerId, data, respond) { + console.log(`MASTER::Received data from worker ${workerId}:`, data); + if (data.fail) { + var err = new Error('Failure from master'); + err.name = 'MasterFailureError'; + respond(err); + } else if (!data.doNothing) { + + respond(null, { + qwerty: 123456 + }); + } +}); + +var packet = { + id: 0, + name: 'SocketCluster' +}; + +console.log('MASTER::Sending packet to worker 0'); +socketCluster.sendToWorker(0, packet, function (err, data) { + console.log('MASTER::Response error from worker 0:', err); + console.log('MASTER::Response data from worker 0:', data); +}); + +console.log('MASTER::Sending packet to worker 1'); +socketCluster.sendToWorker(1, packet, function (err, data) { + console.log('MASTER::Response error from worker 1:', err); + console.log('MASTER::Response data from worker 1:', data); +}); + +console.log('MASTER::Sending packet to non-existent worker 2'); +socketCluster.sendToWorker(2, packet, function (err, data) { + console.log('MASTER::Response error from non-existent worker 2:', err); + console.log('MASTER::Response data from non-existent worker 2:', data); +}); + +var errorPacket = { + fail: true +}; + +console.log('MASTER::Sending error-causing packet to worker 0'); +socketCluster.sendToWorker(0, errorPacket, function (err, data) { + console.log('MASTER::Error response error from worker 0:', err); + console.log('MASTER::Error response data from worker 0:', data); +}); + +console.log('MASTER::Sending error-causing packet to worker 0 without callback'); +socketCluster.sendToWorker(0, errorPacket); + +var timeoutPacket = { + doNothing: true +}; + +console.log('MASTER::Sending timeout-causing packet to worker 0'); +socketCluster.sendToWorker(0, timeoutPacket, function (err, data) { + console.log('MASTER::Timeout response error from worker 0:', err); + console.log('MASTER::Timeout response data from worker 0:', data); +}); + +console.log('MASTER::Sending timeout-causing packet to worker 0 without callback'); +socketCluster.sendToWorker(0, timeoutPacket); diff --git a/test/internal/serverToWorker.js b/test/internal/serverToWorker.js deleted file mode 100644 index a17f0458..00000000 --- a/test/internal/serverToWorker.js +++ /dev/null @@ -1,42 +0,0 @@ -var SocketCluster = require('../../index').SocketCluster; - -var socketCluster = new SocketCluster({ - workers: 3, - brokers: 3, - port: 8000, - appName: 'myapp', - workerController: __dirname + '/worker.js', - //brokerController: __dirname + '/broker.js', - socketChannelLimit: 100, - crashWorkerOnError: true, - rebootWorkerOnCrash: true -}); - -socketCluster.on('workerClusterReady',function () { - - var packet = { - id:0, - name:'SocketCluster' - } - - console.log('MASTER::Sending packet to worker 0') - socketCluster.sendToWorker(0,packet,function(workerId,data) { - console.log(`MASTER::Worker ${ workerId } data packet`) - console.log(data) - console.log('MASTER::End data packet') - }); - - console.log('MASTER::Sending packet to worker 1') - socketCluster.sendToWorker(1,packet,function(workerId,data) { - console.log(`MASTER::Worker ${ workerId } data packet`) - console.log(data) - console.log('MASTER::End data packet') - }); - - console.log('MASTER::Sending packet to worker 2') - socketCluster.sendToWorker(2,packet,function(workerId,data) { - console.log(`MASTER::Worker ${ workerId } data packet`) - console.log(data) - console.log('MASTER::End data packet') - }); -}); \ No newline at end of file diff --git a/test/internal/testsocketpath.js b/test/internal/test-socket-path.js similarity index 100% rename from test/internal/testsocketpath.js rename to test/internal/test-socket-path.js diff --git a/test/internal/worker.js b/test/internal/worker.js index f08cd73b..c0c02f9d 100644 --- a/test/internal/worker.js +++ b/test/internal/worker.js @@ -2,16 +2,59 @@ var fs = require('fs'); module.exports.run = function (worker) { console.log(' >> Worker PID:', process.pid); - + // Get a reference to our raw Node HTTP server var httpServer = worker.getHTTPServer(); // Get a reference to our WebSocket server var wsServer = worker.getSCServer(); - worker.on('masterMessage',function(data,res) { - console.log('WORKER::Received data packet from server') - console.log(arguments) - console.log('WORKER::Responding back to server.') - res && res({ id:1,name:'TestName' }) + worker.on('masterMessage', function (data, res) { + console.log(`WORKER ${worker.id}::Received data from master:`, data); + if (data.fail) { + var err = new Error('This is an error from worker'); + err.name = 'MyCustomWorkerError'; + res(err); + } else if (!data.doNothing) { + res(null, { + id: 1, + name: 'TestName' + }); + } + }); + + var packet = { + prop: 1234 + }; + + console.log(`WORKER ${worker.id}::Sending packet to master`); + worker.sendToMaster(packet, function (err, data) { + console.log(`WORKER ${worker.id}::Response error from master:`, err); + console.log(`WORKER ${worker.id}::Response data packet from master:`, data); + }); + + var timeoutPacket = { + doNothing: true + }; + + console.log(`WORKER ${worker.id}::Sending timeout-causing packet to master`); + worker.sendToMaster(timeoutPacket, function (err, data) { + console.log(`WORKER ${worker.id}::Timeout response error from master:`, err); + console.log(`WORKER ${worker.id}::Timeout response data packet from master:`, data); + }); + + console.log(`WORKER ${worker.id}::Sending timeout-causing packet to master without callback`); + worker.sendToMaster(timeoutPacket); + + var errorPacket = { + fail: true + }; + + console.log(`WORKER ${worker.id}::Sending error-causing packet to master`); + worker.sendToMaster(errorPacket, function (err, data) { + console.log(`WORKER ${worker.id}::Error response error from master:`, err); + console.log(`WORKER ${worker.id}::Error response data packet from master:`, data); }); -}; \ No newline at end of file + + console.log(`WORKER ${worker.id}::Sending error-causing packet to master without callback`); + worker.sendToMaster(errorPacket); +}; diff --git a/test/internal/worker2.js b/test/internal/worker2.js new file mode 100644 index 00000000..c96da4b5 --- /dev/null +++ b/test/internal/worker2.js @@ -0,0 +1,11 @@ +var fs = require('fs'); + +module.exports.run = function (worker) { + console.log(' >> Worker PID:', process.pid); + + // Get a reference to our raw Node HTTP server + var httpServer = worker.getHTTPServer(); + // Get a reference to our WebSocket server + var wsServer = worker.getSCServer(); + +};