Skip to content

Commit 8d67776

Browse files
flovilmartArthur Cinader
authored andcommitted
Removes un-necessary shutdown handler (#3786)
* Removes un-necessary shutdown handler - When registering a shutdown hander, the node process has to be exited manually which causes issues for many users * Proper graceful shutdown from CLI
1 parent 864d191 commit 8d67776

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,6 @@ export class MongoStorageAdapter {
9797

9898
// MaxTimeMS is not a global MongoDB client option, it is applied per operation.
9999
this._maxTimeMS = mongoOptions.maxTimeMS;
100-
process.on('SIGTERM', this.handleShutdown(this));
101-
process.on('SIGINT', this.handleShutdown(this));
102-
}
103-
104-
handleShutdown(storageAdapter) {
105-
return () => {
106-
if (!storageAdapter.database) {
107-
return;
108-
}
109-
storageAdapter.database.close(false);
110-
}
111100
}
112101

113102
connect() {
@@ -139,6 +128,13 @@ export class MongoStorageAdapter {
139128
return this.connectionPromise;
140129
}
141130

131+
handleShutdown() {
132+
if (!this.database) {
133+
return;
134+
}
135+
this.database.close(false);
136+
}
137+
142138
_adaptiveCollection(name: string) {
143139
return this.connect()
144140
.then(() => this.database.collection(this._collectionPrefix + name))

src/ParseServer.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,13 @@ class ParseServer {
313313
return ParseServer.app(this.config);
314314
}
315315

316+
handleShutdown() {
317+
const { adapter } = this.config.databaseController;
318+
if (adapter && typeof adapter.handleShutdown === 'function') {
319+
adapter.handleShutdown();
320+
}
321+
}
322+
316323
static app({maxUploadSize = '20mb', appId}) {
317324
// This app serves the Parse API directly.
318325
// It's the equivalent of https://api.parse.com/1 in the hosted Parse API.

src/cli/parse-server.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable no-console */
22
import express from 'express';
3-
import { ParseServer } from '../index';
3+
import ParseServer from '../index';
44
import definitions from './definitions/parse-server';
55
import cluster from 'cluster';
66
import os from 'os';
@@ -43,9 +43,9 @@ function startServer(options, callback) {
4343
app.use(middleware);
4444
}
4545

46-
const api = new ParseServer(options);
46+
const parseServer = new ParseServer(options);
4747
const sockets = {};
48-
app.use(options.mountPath, api);
48+
app.use(options.mountPath, parseServer.app);
4949

5050
const server = app.listen(options.port, options.host, callback);
5151
server.on('connection', initializeConnections);
@@ -85,6 +85,7 @@ function startServer(options, callback) {
8585
console.log('Termination signal received. Shutting down.');
8686
destroyAliveConnections();
8787
server.close();
88+
parseServer.handleShutdown();
8889
};
8990
process.on('SIGTERM', handleShutdown);
9091
process.on('SIGINT', handleShutdown);

0 commit comments

Comments
 (0)