mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-29 16:08:22 +01:00
Make the Aphlict server more resilient.
Summary: Currently, the Aphlict server will crash if invalid JSON data is `POST`ed to it. I have fixed this to, instead, return a 400. Also made some minor formatting changes. Ref T4324. Ref T5284. Also, modify the data structure that is passed around (i.e. `POST`ed to the Aphlict server and broadcast to the Aphlict clients) to include the subscribers. Initially, I figured that we shouldn't expose this information to the clients... however, it is necessary for T4324 that the `AphlictMaster` is able to route a notification to the appropriate clients. Test Plan: Making the following `curl` request: `curl --data "{" http://localhost:22281/`. **Before** ``` sudo ./bin/aphlict debug Starting Aphlict server in foreground... Launching server: $ 'nodejs' '/usr/src/phabricator/src/applications/aphlict/management/../../../../support/aphlict/server/aphlict_server.js' --port='22280' --admin='22281' --host='localhost' --user='aphlict' [Wed Jun 11 2014 17:07:51 GMT+0000 (UTC)] Started Server (PID 2033) [Wed Jun 11 2014 17:07:55 GMT+0000 (UTC)] <<< UNCAUGHT EXCEPTION! >>> SyntaxError: Unexpected end of input >>> Server exited! ``` **After** (No output... the bad JSON is caught and a 400 is returned) Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T4324, T5284 Differential Revision: https://secure.phabricator.com/D9480
This commit is contained in:
parent
bb06e36986
commit
ab4324148a
10 changed files with 65 additions and 62 deletions
|
@ -476,7 +476,7 @@ return array(
|
||||||
'rsrc/js/phuix/PHUIXActionListView.js' => 'b5c256b8',
|
'rsrc/js/phuix/PHUIXActionListView.js' => 'b5c256b8',
|
||||||
'rsrc/js/phuix/PHUIXActionView.js' => '6e8cefa4',
|
'rsrc/js/phuix/PHUIXActionView.js' => '6e8cefa4',
|
||||||
'rsrc/js/phuix/PHUIXDropdownMenu.js' => 'bd4c8dca',
|
'rsrc/js/phuix/PHUIXDropdownMenu.js' => 'bd4c8dca',
|
||||||
'rsrc/swf/aphlict.swf' => 'b7c2d7aa',
|
'rsrc/swf/aphlict.swf' => 'f45c3edc',
|
||||||
),
|
),
|
||||||
'symbols' =>
|
'symbols' =>
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -176,10 +176,8 @@ final class PhabricatorFeedStoryPublisher {
|
||||||
|
|
||||||
private function sendNotification($chrono_key) {
|
private function sendNotification($chrono_key) {
|
||||||
$data = array(
|
$data = array(
|
||||||
'data' => array(
|
|
||||||
'key' => (string)$chrono_key,
|
'key' => (string)$chrono_key,
|
||||||
'type' => 'notification',
|
'type' => 'notification',
|
||||||
),
|
|
||||||
'subscribers' => $this->subscribedPHIDs,
|
'subscribers' => $this->subscribedPHIDs,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
final class PhabricatorNotificationClient {
|
final class PhabricatorNotificationClient {
|
||||||
|
|
||||||
const EXPECT_VERSION = 5;
|
const EXPECT_VERSION = 6;
|
||||||
|
|
||||||
public static function getServerStatus() {
|
public static function getServerStatus() {
|
||||||
$uri = PhabricatorEnv::getEnvConfig('notification.server-uri');
|
$uri = PhabricatorEnv::getEnvConfig('notification.server-uri');
|
||||||
|
|
|
@ -107,8 +107,6 @@ var messages_in = 0;
|
||||||
var start_time = new Date().getTime();
|
var start_time = new Date().getTime();
|
||||||
|
|
||||||
var receive_server = http.createServer(function(request, response) {
|
var receive_server = http.createServer(function(request, response) {
|
||||||
response.writeHead(200, {'Content-Type' : 'text/plain'});
|
|
||||||
|
|
||||||
// Publishing a notification.
|
// Publishing a notification.
|
||||||
if (request.method == 'POST') {
|
if (request.method == 'POST') {
|
||||||
var body = '';
|
var body = '';
|
||||||
|
@ -118,12 +116,20 @@ var receive_server = http.createServer(function(request, response) {
|
||||||
});
|
});
|
||||||
|
|
||||||
request.on('end', function() {
|
request.on('end', function() {
|
||||||
++messages_in;
|
try {
|
||||||
|
|
||||||
var msg = JSON.parse(body);
|
var msg = JSON.parse(body);
|
||||||
|
|
||||||
debug.log('notification: ' + JSON.stringify(msg));
|
debug.log('notification: ' + JSON.stringify(msg));
|
||||||
broadcast(msg.data);
|
++messages_in;
|
||||||
|
broadcast(msg);
|
||||||
|
|
||||||
|
response.writeHead(200, {'Content-Type': 'text/plain'});
|
||||||
|
} catch (err) {
|
||||||
|
response.statusCode = 400;
|
||||||
|
response.write('400 Bad Request');
|
||||||
|
} finally {
|
||||||
response.end();
|
response.end();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else if (request.url == '/status/') {
|
} else if (request.url == '/status/') {
|
||||||
request.on('data', function(data) {
|
request.on('data', function(data) {
|
||||||
|
@ -139,9 +145,10 @@ var receive_server = http.createServer(function(request, response) {
|
||||||
'messages.in': messages_in,
|
'messages.in': messages_in,
|
||||||
'messages.out': messages_out,
|
'messages.out': messages_out,
|
||||||
'log': config.log,
|
'log': config.log,
|
||||||
'version': 5
|
'version': 6
|
||||||
};
|
};
|
||||||
|
|
||||||
|
response.writeHead(200, {'Content-Type': 'text/plain'});
|
||||||
response.write(JSON.stringify(status));
|
response.write(JSON.stringify(status));
|
||||||
response.end();
|
response.end();
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,9 +13,7 @@ JX.install('AphlictListenerList', {
|
||||||
_totalListenerCount: 0,
|
_totalListenerCount: 0,
|
||||||
|
|
||||||
addListener: function(socket) {
|
addListener: function(socket) {
|
||||||
var listener = new JX.AphlictListener(
|
var listener = new JX.AphlictListener(this._generateNextID(), socket);
|
||||||
this._generateNextID(),
|
|
||||||
socket);
|
|
||||||
|
|
||||||
this._listeners[listener.getID()] = listener;
|
this._listeners[listener.getID()] = listener;
|
||||||
this._activeListenerCount++;
|
this._activeListenerCount++;
|
||||||
|
|
Binary file not shown.
Loading…
Add table
Reference in a new issue