Skip to content

Commit d709eb3

Browse files
committed
v6.8.0
1 parent bdc8c86 commit d709eb3

File tree

6 files changed

+1220
-59
lines changed

6 files changed

+1220
-59
lines changed

index.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
var path = require('path');
22
var crypto = require('crypto');
33
var EventEmitter = require('events').EventEmitter;
4-
var domain = require('sc-domain');
54
var uuid = require('uuid');
65
var fork = require('child_process').fork;
76
var os = require('os');
@@ -49,18 +48,18 @@ var SocketCluster = function (options) {
4948
'EADDRINUSE': 'Failed to bind to a port because it was already used by another process.'
5049
};
5150

52-
self._errorDomain = domain.create();
53-
self._errorDomain.on('error', function (err) {
54-
self.errorHandler(err, {
51+
self.on('error', function (error) {
52+
self.emitFail(error, {
5553
type: 'Master',
5654
pid: process.pid
5755
});
5856
});
5957

60-
self._errorDomain.add(self);
61-
62-
self._errorDomain.run(function () {
58+
// Capture any errors that are thrown during initialization.
59+
new Promise(function () {
6360
self._init(options);
61+
}).catch(function (error) {
62+
self.emit('error', error);
6463
});
6564
};
6665

@@ -309,7 +308,7 @@ SocketCluster.prototype._init = function (options) {
309308
}
310309

311310
process.stdin.on('error', function (err) {
312-
self.warningHandler(err, {
311+
self.emitWarning(err, {
313312
type: 'Master',
314313
pid: process.pid
315314
});
@@ -397,7 +396,6 @@ SocketCluster.prototype._convertValueToUnknownError = function (err, origin) {
397396
if (!(err instanceof Error)) {
398397
if (err && typeof err == 'object') {
399398
if (err.message || err.stack) {
400-
// TODO 2
401399
err = scErrors.hydrateError(err, true);
402400
} else {
403401
// If err has neither a stack nor a message property
@@ -433,7 +431,7 @@ SocketCluster.prototype._convertValueToUnknownError = function (err, origin) {
433431
return err;
434432
};
435433

436-
SocketCluster.prototype.errorHandler = function (err, origin) {
434+
SocketCluster.prototype.emitFail = function (err, origin) {
437435
err = this._convertValueToUnknownError(err, origin);
438436

439437
var annotation = this._errorAnnotations[err.code];
@@ -446,7 +444,7 @@ SocketCluster.prototype.errorHandler = function (err, origin) {
446444
this._logObject(err, 'Error');
447445
};
448446

449-
SocketCluster.prototype.warningHandler = function (warning, origin) {
447+
SocketCluster.prototype.emitWarning = function (warning, origin) {
450448
warning = this._convertValueToUnknownError(warning, origin);
451449

452450
this.emit(this.EVENT_WARNING, warning);
@@ -457,28 +455,28 @@ SocketCluster.prototype.warningHandler = function (warning, origin) {
457455
};
458456

459457
SocketCluster.prototype._workerClusterErrorHandler = function (pid, error) {
460-
this.errorHandler(error, {
458+
this.emitFail(error, {
461459
type: 'WorkerCluster',
462460
pid: pid
463461
});
464462
};
465463

466464
SocketCluster.prototype._workerErrorHandler = function (workerPid, error) {
467-
this.errorHandler(error, {
465+
this.emitFail(error, {
468466
type: 'Worker',
469467
pid: workerPid
470468
});
471469
};
472470

473471
SocketCluster.prototype._brokerEngineErrorHandler = function (pid, error) {
474-
this.errorHandler(error, {
472+
this.emitFail(error, {
475473
type: 'BrokerEngine',
476474
pid: pid
477475
});
478476
};
479477

480478
SocketCluster.prototype._brokerErrorHandler = function (brokerPid, error) {
481-
this.errorHandler(error, {
479+
this.emitFail(error, {
482480
type: 'Broker',
483481
pid: brokerPid
484482
});
@@ -489,7 +487,7 @@ SocketCluster.prototype._workerWarningHandler = function (workerPid, warning) {
489487
type: 'Worker',
490488
pid: workerPid
491489
};
492-
this.warningHandler(warning, origin);
490+
this.emitWarning(warning, origin);
493491
};
494492

495493
SocketCluster.prototype._workerClusterReadyHandler = function () {
@@ -509,7 +507,7 @@ SocketCluster.prototype._workerClusterReadyHandler = function () {
509507

510508
var warning = new ProcessExitError(warningMessage);
511509

512-
self.warningHandler(warning, {
510+
self.emitWarning(warning, {
513511
type: 'Master',
514512
pid: process.pid
515513
});
@@ -571,7 +569,7 @@ SocketCluster.prototype._handleWorkerClusterExit = function (errorCode, signal)
571569
this.log(message);
572570
} else {
573571
var error = new ProcessExitError(message, errorCode);
574-
this.errorHandler(error, {
572+
this.emitFail(error, {
575573
type: 'WorkerCluster',
576574
pid: wcPid
577575
});

kubernetes/socketcluster-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ spec:
1111
spec:
1212
containers:
1313
- name: socketcluster
14-
image: socketcluster/socketcluster:v6.7.1
14+
image: socketcluster/socketcluster:v6.8.0
1515
ports:
1616
- containerPort: 8000
1717
env:

lib/scworker.js

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
var socketClusterServer = require('socketcluster-server');
22
var EventEmitter = require('events').EventEmitter;
33
var crypto = require('crypto');
4-
var domain = require('sc-domain');
54
var uuid = require('uuid');
65
var http = require('http');
76
var https = require('https');
@@ -31,15 +30,7 @@ var SCWorker = function (options) {
3130
this.type = 'worker';
3231
self._pendingResponseHandlers = {};
3332

34-
this._errorDomain = domain.create();
35-
this._errorDomain.on('error', function () {
36-
self.errorHandler.apply(self, arguments);
37-
});
38-
39-
this.start = this._errorDomain.bind(this._start);
40-
this._errorDomain.run(function () {
41-
self._init(options);
42-
});
33+
this._init(options);
4334
};
4435

4536
SCWorker.prototype = Object.create(EventEmitter.prototype);
@@ -77,9 +68,9 @@ SCWorker.prototype._init = function (options) {
7768
try {
7869
process.setuid(this.options.downgradeToUser);
7970
} catch (err) {
80-
this._errorDomain.emit('error', new InvalidActionError('Could not downgrade to user "' + this.options.downgradeToUser +
71+
throw new InvalidActionError('Could not downgrade to user "' + this.options.downgradeToUser +
8172
'" - Either this user does not exist or the current process does not have the permission' +
82-
' to switch to it.'));
73+
' to switch to it'); // TODO 2 test this
8374
}
8475
}
8576

@@ -106,10 +97,10 @@ SCWorker.prototype._init = function (options) {
10697
} else {
10798
error = err;
10899
}
109-
self._errorDomain.emit('error', error);
100+
self.emitError(error);
110101
});
111102
this.brokerEngineClient.on('warning', function (warning) {
112-
self.warningHandler(warning);
103+
self.emitWarning(warning);
113104
});
114105
this.exchange = this.global = this.brokerEngineClient.exchange();
115106

@@ -128,15 +119,14 @@ SCWorker.prototype._init = function (options) {
128119

129120
this.httpServer.exchange = this.httpServer.global = this.exchange;
130121

131-
var httpServerErrorDomain = domain.create();
132-
httpServerErrorDomain.add(this.httpServer);
133-
httpServerErrorDomain.on('error', function (err) {
122+
this.httpServer.on('error', function (err) {
123+
var error;
134124
if (typeof err == 'string') {
135125
error = new HTTPServerError(err);
136126
} else {
137127
error = err;
138128
}
139-
self._errorDomain.emit('error', error);
129+
self.emitError(error);
140130
});
141131

142132
var secure = this.options.protocol == 'https' ? 1 : 0;
@@ -172,6 +162,9 @@ SCWorker.prototype._init = function (options) {
172162
this.setAuthEngine(new AuthEngine());
173163
this.codec = this.scServer.codec;
174164

165+
this._socketPath = this.scServer.getPath();
166+
this._socketPathRegex = new RegExp('^' + this._socketPath);
167+
175168
this.scServer.on('_connection', function (socket) {
176169
// The connection event counts as a WS request
177170
self._wsRequestCount++;
@@ -181,15 +174,12 @@ SCWorker.prototype._init = function (options) {
181174
self.emit(self.EVENT_CONNECTION, socket);
182175
});
183176

184-
this.scServer.on('warning', function () {
185-
self.warningHandler.apply(self, arguments);
177+
this.scServer.on('warning', function (warning) {
178+
self.emitWarning(warning);
179+
});
180+
this.scServer.on('error', function (error) {
181+
self.emitError(error);
186182
});
187-
188-
this._socketPath = this.scServer.getPath();
189-
this._socketPathRegex = new RegExp('^' + this._socketPath);
190-
191-
this._errorDomain.add(this.scServer);
192-
193183
this.scServer.on('ready', function () {
194184
self.emit(self.EVENT_READY);
195185
});
@@ -257,7 +247,7 @@ SCWorker.prototype._startServer = function () {
257247
}
258248
};
259249

260-
SCWorker.prototype._start = function () {
250+
SCWorker.prototype.start = function () {
261251
var self = this;
262252

263253
this._httpRequestCount = 0;
@@ -335,7 +325,7 @@ SCWorker.prototype._calculateStatus = function () {
335325
message += 'usage of ' + memoryUsage.heapUsed + ' exceeded ';
336326
message += 'the killWorkerMemoryThreshold of ' + memThreshold;
337327
var warning = new ResourceLimitError(message);
338-
this.warningHandler(warning);
328+
this.emitWarning(warning);
339329
process.exit();
340330
}
341331
}
@@ -415,11 +405,11 @@ SCWorker.prototype.handleMasterMessage = function (message) {
415405
});
416406
};
417407

418-
SCWorker.prototype.errorHandler = function (err) {
408+
SCWorker.prototype.emitError = function (err) {
419409
this.emit(this.EVENT_ERROR, err);
420410
};
421411

422-
SCWorker.prototype.warningHandler = function (warning) {
412+
SCWorker.prototype.emitWarning = function (warning) {
423413
this.emit(this.EVENT_WARNING, warning);
424414
};
425415

0 commit comments

Comments
 (0)