Skip to content

Commit e7a45ce

Browse files
flovilmartArthur Cinader
authored andcommitted
Adds graceful shutdown handler for mongodb (#3706)
1 parent 906fb27 commit e7a45ce

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ 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+
}
100111
}
101112

102113
connect() {

0 commit comments

Comments
 (0)