Skip to content

Commit bae19f2

Browse files
authored
Clear the connectionPromise upon close or error (#2314)
1 parent 0f49f31 commit bae19f2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

+13
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,20 @@ export class MongoStorageAdapter {
105105
const encodedUri = formatUrl(parseUrl(this._uri));
106106

107107
this.connectionPromise = MongoClient.connect(encodedUri, this._mongoOptions).then(database => {
108+
if (!database) {
109+
delete this.connectionPromise;
110+
return;
111+
}
112+
database.on('error', (error) => {
113+
delete this.connectionPromise;
114+
});
115+
database.on('close', (error) => {
116+
delete this.connectionPromise;
117+
});
108118
this.database = database;
119+
}).catch((err) => {
120+
delete this.connectionPromise;
121+
return Promise.reject(err);
109122
});
110123

111124
return this.connectionPromise;

0 commit comments

Comments
 (0)