Namespace Aphlict clients by request path, plus other fixes
Summary: Fixes T7130. Fixes T7041. Fixes T7012. Major change here is partitioning clients. In the Phacility cluster, being able to get a huge pile of instances on a single server -- without needing to run a process per instance -- is desirable. To accomplish this, just bucket clients by the path they connect with. This will let us set client URIs to `/instancename/` and then route connections to a small set of servers. This degrades cleanly in the common case and has no effect on installs which don't do instancing. Also fix two unrelated issues: - Fix the timeouts, which were incorrectly initializing in `open()` (which is called during reconnect, causing them to reset every time). Instead, initialize in the constructor. Cap timeout at 5 minutes. - Probably fix subscriptions, which were using a property with an object definition. Since this is by-ref, all concrete instances of the object share the same property, so all users would be subscribed to everything. Probably. Test Plan: - Hit notification status page, saw version bump and instance/path name. - Saw instance/path name in client and server logs. - Stopped server, saw reconnects after 2, 4, 16, ... seconds. - Sent test notification; received test notification. - Didn't explicitly test the subscription thing but it should be obvious by looking at `/notification/status/` shortly after a push. Reviewers: joshuaspence, btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7041, T7012, T7130 Differential Revision: https://secure.phabricator.com/D11769
This commit is contained in:
@@ -5,19 +5,28 @@ var JX = require('./javelin').JX;
|
||||
require('./AphlictListenerList');
|
||||
require('./AphlictLog');
|
||||
|
||||
var url = require('url');
|
||||
var util = require('util');
|
||||
var WebSocket = require('ws');
|
||||
|
||||
JX.install('AphlictClientServer', {
|
||||
|
||||
construct: function(server) {
|
||||
this.setListenerList(new JX.AphlictListenerList());
|
||||
this.setLogger(new JX.AphlictLog());
|
||||
this._server = server;
|
||||
this._lists = {};
|
||||
},
|
||||
|
||||
members: {
|
||||
_server: null,
|
||||
_lists: null,
|
||||
|
||||
getListenerList: function(path) {
|
||||
if (!this._lists[path]) {
|
||||
this._lists[path] = new JX.AphlictListenerList(path);
|
||||
}
|
||||
return this._lists[path];
|
||||
},
|
||||
|
||||
listen: function() {
|
||||
var self = this;
|
||||
@@ -25,7 +34,8 @@ JX.install('AphlictClientServer', {
|
||||
var wss = new WebSocket.Server({server: server});
|
||||
|
||||
wss.on('connection', function(ws) {
|
||||
var listener = self.getListenerList().addListener(ws);
|
||||
var path = url.parse(ws.upgradeReq.url).pathname;
|
||||
var listener = self.getListenerList(path).addListener(ws);
|
||||
|
||||
function log() {
|
||||
self.getLogger().log(
|
||||
@@ -70,12 +80,12 @@ JX.install('AphlictClientServer', {
|
||||
});
|
||||
|
||||
ws.on('close', function() {
|
||||
self.getListenerList().removeListener(listener);
|
||||
self.getListenerList(path).removeListener(listener);
|
||||
log('Disconnected.');
|
||||
});
|
||||
|
||||
wss.on('close', function() {
|
||||
self.getListenerList().removeListener(listener);
|
||||
self.getListenerList(path).removeListener(listener);
|
||||
log('Disconnected.');
|
||||
});
|
||||
|
||||
@@ -90,7 +100,6 @@ JX.install('AphlictClientServer', {
|
||||
},
|
||||
|
||||
properties: {
|
||||
listenerList: null,
|
||||
logger: null,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user