mirror of https://github.com/TryGhost/Ghost.git
Removed unused connection handling + restart method
- Connection handling is legacy code added in 1438278ce4
- Although we were tracking all connections in memory, we weren't actually closing any because stop isn't called
- This (and restart) were both added as part of the now long-deprecated system for using Ghost directly as an npm module
- If we want to close connections cleanly, we should use a tool to do this
This commit is contained in:
parent
71f02d25e9
commit
f8cdaf0c24
|
@ -22,8 +22,6 @@ const bootstrapSocket = require('@tryghost/bootstrap-socket');
|
||||||
function GhostServer(rootApp) {
|
function GhostServer(rootApp) {
|
||||||
this.rootApp = rootApp;
|
this.rootApp = rootApp;
|
||||||
this.httpServer = null;
|
this.httpServer = null;
|
||||||
this.connections = {};
|
|
||||||
this.connectionId = 0;
|
|
||||||
|
|
||||||
// Expose config module for use externally.
|
// Expose config module for use externally.
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
@ -97,7 +95,7 @@ GhostServer.prototype.start = function (externalApp) {
|
||||||
|
|
||||||
reject(ghostError);
|
reject(ghostError);
|
||||||
});
|
});
|
||||||
self.httpServer.on('connection', self.connection.bind(self));
|
|
||||||
self.httpServer.on('listening', function () {
|
self.httpServer.on('listening', function () {
|
||||||
debug('...Started');
|
debug('...Started');
|
||||||
self.logStartMessages();
|
self.logStartMessages();
|
||||||
|
@ -129,23 +127,10 @@ GhostServer.prototype.stop = function () {
|
||||||
self.logShutdownMessages();
|
self.logShutdownMessages();
|
||||||
resolve(self);
|
resolve(self);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.closeConnections();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* ### Restart
|
|
||||||
* Restarts the ghost application
|
|
||||||
* @returns {Promise} Resolves once Ghost has restarted
|
|
||||||
*/
|
|
||||||
GhostServer.prototype.restart = function () {
|
|
||||||
return this.stop().then(function (ghostServer) {
|
|
||||||
return ghostServer.start();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ### Hammertime
|
* ### Hammertime
|
||||||
* To be called after `stop`
|
* To be called after `stop`
|
||||||
|
@ -156,42 +141,6 @@ GhostServer.prototype.hammertime = function () {
|
||||||
return Promise.resolve(this);
|
return Promise.resolve(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* ## Private (internal) methods
|
|
||||||
*
|
|
||||||
* ### Connection
|
|
||||||
* @param {Object} socket
|
|
||||||
*/
|
|
||||||
GhostServer.prototype.connection = function (socket) {
|
|
||||||
const self = this;
|
|
||||||
|
|
||||||
self.connectionId += 1;
|
|
||||||
socket._ghostId = self.connectionId;
|
|
||||||
|
|
||||||
socket.on('close', function () {
|
|
||||||
delete self.connections[this._ghostId];
|
|
||||||
});
|
|
||||||
|
|
||||||
self.connections[socket._ghostId] = socket;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ### Close Connections
|
|
||||||
* Most browsers keep a persistent connection open to the server, which prevents the close callback of
|
|
||||||
* httpServer from returning. We need to destroy all connections manually.
|
|
||||||
*/
|
|
||||||
GhostServer.prototype.closeConnections = function () {
|
|
||||||
const self = this;
|
|
||||||
|
|
||||||
Object.keys(self.connections).forEach(function (socketId) {
|
|
||||||
const socket = self.connections[socketId];
|
|
||||||
|
|
||||||
if (socket) {
|
|
||||||
socket.destroy();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ### Log Start Messages
|
* ### Log Start Messages
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue