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:
Hannah Wolfe 2020-08-07 19:50:09 +01:00
parent 71f02d25e9
commit f8cdaf0c24
1 changed files with 1 additions and 52 deletions

View File

@ -22,8 +22,6 @@ const bootstrapSocket = require('@tryghost/bootstrap-socket');
function GhostServer(rootApp) {
this.rootApp = rootApp;
this.httpServer = null;
this.connections = {};
this.connectionId = 0;
// Expose config module for use externally.
this.config = config;
@ -97,7 +95,7 @@ GhostServer.prototype.start = function (externalApp) {
reject(ghostError);
});
self.httpServer.on('connection', self.connection.bind(self));
self.httpServer.on('listening', function () {
debug('...Started');
self.logStartMessages();
@ -129,23 +127,10 @@ GhostServer.prototype.stop = function () {
self.logShutdownMessages();
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
* To be called after `stop`
@ -156,42 +141,6 @@ GhostServer.prototype.hammertime = function () {
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
*/