Skip to content

Commit

Permalink
Clear the connectionPromise upon close or error (parse-community#2314)
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart authored and Rafael Santos committed Mar 15, 2017
1 parent a872093 commit 4cb08d9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,20 @@ export class MongoStorageAdapter {
const encodedUri = formatUrl(parseUrl(this._uri));

this.connectionPromise = MongoClient.connect(encodedUri, this._mongoOptions).then(database => {
if (!database) {
delete this.connectionPromise;
return;
}
database.on('error', (error) => {
delete this.connectionPromise;
});
database.on('close', (error) => {
delete this.connectionPromise;
});
this.database = database;
}).catch((err) => {
delete this.connectionPromise;
return Promise.reject(err);
});

return this.connectionPromise;
Expand Down

0 comments on commit 4cb08d9

Please sign in to comment.