Skip to content

Commit

Permalink
feat: run "stop" when startup throws a error
Browse files Browse the repository at this point in the history
  • Loading branch information
hasezoey committed Jan 15, 2022
1 parent ca38110 commit 235a09f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,13 @@ export class MongoMemoryReplSet extends EventEmitter implements ManagerAdvanced
await ensureAsync()
.then(() => this.initAllServers())
.then(() => this._initReplSet())
.catch((err) => {
.catch(async (err) => {
if (!debug.enabled('MongoMS:MongoMemoryReplSet')) {
console.warn('Starting the ReplSet failed, enable debug for more information');
}

await this.stop(false); // still try to close the instance that was spawned, without cleanup for investigation

this.stateChange(MongoMemoryReplSetStates.stopped);

throw err;
Expand Down
4 changes: 3 additions & 1 deletion packages/mongodb-memory-server-core/src/MongoMemoryServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,13 @@ export class MongoMemoryServer extends EventEmitter implements ManagerAdvanced {

this.stateChange(MongoMemoryServerStates.starting);

await this._startUpInstance(forceSamePort).catch((err) => {
await this._startUpInstance(forceSamePort).catch(async (err) => {
if (!debug.enabled('MongoMS:MongoMemoryServer')) {
console.warn('Starting the instance failed, enable debug for more information');
}

await this.stop(false); // still try to close the instance that was spawned, without cleanup for investigation

this.stateChange(MongoMemoryServerStates.stopped);

throw err;
Expand Down

0 comments on commit 235a09f

Please sign in to comment.