Skip to content

Commit f8cdaf0

Browse files
committed
Removed unused connection handling + restart method
- Connection handling is legacy code added in TryGhost@1438278 - 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
1 parent 71f02d2 commit f8cdaf0

File tree

1 file changed

+1
-52
lines changed

1 file changed

+1
-52
lines changed

core/server/ghost-server.js

+1-52
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ const bootstrapSocket = require('@tryghost/bootstrap-socket');
2222
function GhostServer(rootApp) {
2323
this.rootApp = rootApp;
2424
this.httpServer = null;
25-
this.connections = {};
26-
this.connectionId = 0;
2725

2826
// Expose config module for use externally.
2927
this.config = config;
@@ -97,7 +95,7 @@ GhostServer.prototype.start = function (externalApp) {
9795

9896
reject(ghostError);
9997
});
100-
self.httpServer.on('connection', self.connection.bind(self));
98+
10199
self.httpServer.on('listening', function () {
102100
debug('...Started');
103101
self.logStartMessages();
@@ -129,23 +127,10 @@ GhostServer.prototype.stop = function () {
129127
self.logShutdownMessages();
130128
resolve(self);
131129
});
132-
133-
self.closeConnections();
134130
}
135131
});
136132
};
137133

138-
/**
139-
* ### Restart
140-
* Restarts the ghost application
141-
* @returns {Promise} Resolves once Ghost has restarted
142-
*/
143-
GhostServer.prototype.restart = function () {
144-
return this.stop().then(function (ghostServer) {
145-
return ghostServer.start();
146-
});
147-
};
148-
149134
/**
150135
* ### Hammertime
151136
* To be called after `stop`
@@ -156,42 +141,6 @@ GhostServer.prototype.hammertime = function () {
156141
return Promise.resolve(this);
157142
};
158143

159-
/**
160-
* ## Private (internal) methods
161-
*
162-
* ### Connection
163-
* @param {Object} socket
164-
*/
165-
GhostServer.prototype.connection = function (socket) {
166-
const self = this;
167-
168-
self.connectionId += 1;
169-
socket._ghostId = self.connectionId;
170-
171-
socket.on('close', function () {
172-
delete self.connections[this._ghostId];
173-
});
174-
175-
self.connections[socket._ghostId] = socket;
176-
};
177-
178-
/**
179-
* ### Close Connections
180-
* Most browsers keep a persistent connection open to the server, which prevents the close callback of
181-
* httpServer from returning. We need to destroy all connections manually.
182-
*/
183-
GhostServer.prototype.closeConnections = function () {
184-
const self = this;
185-
186-
Object.keys(self.connections).forEach(function (socketId) {
187-
const socket = self.connections[socketId];
188-
189-
if (socket) {
190-
socket.destroy();
191-
}
192-
});
193-
};
194-
195144
/**
196145
* ### Log Start Messages
197146
*/

0 commit comments

Comments
 (0)