MCPcopy
hub / github.com/parse-community/parse-server / handleShutdown

Method handleShutdown

src/ParseServer.ts:237–282  ·  view source on GitHub ↗

* Stops the parse server, cancels any ongoing requests and closes all connections. * * Currently, express doesn't shut down immediately after receiving SIGINT/SIGTERM * if it has client connections that haven't timed out. * (This is a known issue with node - https://github.com/nodejs/nod

()

Source from the content-addressed store, hash-verified

235 * @returns {Promise<void>} a promise that resolves when the server is stopped
236 */
237 async handleShutdown() {
238 const serverClosePromise = resolvingPromise();
239 const liveQueryServerClosePromise = resolvingPromise();
240 const promises = [];
241 this.server.close((error) => {
242 /* istanbul ignore next */
243 if (error) {
244 // eslint-disable-next-line no-console
245 console.error('Error while closing parse server', error);
246 }
247 serverClosePromise.resolve();
248 });
249 if (this.liveQueryServer?.server?.close && this.liveQueryServer.server !== this.server) {
250 this.liveQueryServer.server.close((error) => {
251 /* istanbul ignore next */
252 if (error) {
253 // eslint-disable-next-line no-console
254 console.error('Error while closing live query server', error);
255 }
256 liveQueryServerClosePromise.resolve();
257 });
258 } else {
259 liveQueryServerClosePromise.resolve();
260 }
261 const { adapter: databaseAdapter } = this.config.databaseController;
262 if (databaseAdapter && typeof databaseAdapter.handleShutdown === 'function') {
263 promises.push(databaseAdapter.handleShutdown());
264 }
265 const { adapter: fileAdapter } = this.config.filesController;
266 if (fileAdapter && typeof fileAdapter.handleShutdown === 'function') {
267 promises.push(fileAdapter.handleShutdown());
268 }
269 const { adapter: cacheAdapter } = this.config.cacheController;
270 if (cacheAdapter && typeof cacheAdapter.handleShutdown === 'function') {
271 promises.push(cacheAdapter.handleShutdown());
272 }
273 if (this.liveQueryServer) {
274 promises.push(this.liveQueryServer.shutdown());
275 }
276 await Promise.all(promises);
277 connections.destroyAll();
278 await Promise.all([serverClosePromise, liveQueryServerClosePromise]);
279 if (this.config.serverCloseComplete) {
280 this.config.serverCloseComplete();
281 }
282 }
283
284 /**
285 * @static

Callers 8

serverFunction · 0.45
handleShutdownFunction · 0.45
shutdownServerFunction · 0.45

Calls 5

resolvingPromiseFunction · 0.90
errorMethod · 0.80
shutdownMethod · 0.80
destroyAllMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected