Skip to content

Commit c6010f4

Browse files
committed
fix(MongoInstance): add call to "instanceFailed" to "closeHandler"
- add an call to "instanceFailed" into "closeHandler" to ensure the "launch" promise resolves - add an timeout to "kill_internal" - always call "kill_internal" if the childprocess's are defined fixes #385
1 parent fd865af commit c6010f4

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/mongodb-memory-server-core/src/util/MongoInstance.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,26 @@ export default class MongoInstance {
150150
*/
151151
async function kill_internal(process: ChildProcess, name: string, debug: DebugFn) {
152152
await new Promise((resolve) => {
153+
const timeout = setTimeout(() => {
154+
debug('kill_internal timeout triggered');
155+
resolve();
156+
}, 1000 * 10);
153157
process.once(`exit`, (code, signal) => {
154158
debug(`- ${name}: got exit signal, Code: ${code}, Signal: ${signal}`);
159+
clearTimeout(timeout);
155160
resolve();
156161
});
157162
debug(`- ${name}: send "SIGINT"`);
158163
process.kill('SIGINT');
159164
});
160165
}
161166

162-
if (this.childProcess && !this.childProcess.killed) {
167+
if (!isNullOrUndefined(this.childProcess)) {
163168
await kill_internal(this.childProcess, 'childProcess', this.debug);
164169
} else {
165170
this.debug('- childProcess: nothing to shutdown, skipping.');
166171
}
167-
if (this.killerProcess && !this.killerProcess.killed) {
172+
if (!isNullOrUndefined(this.killerProcess)) {
168173
await kill_internal(this.killerProcess, 'killerProcess', this.debug);
169174
} else {
170175
this.debug('- killerProcess: nothing to shutdown, skipping.');
@@ -265,6 +270,7 @@ export default class MongoInstance {
265270
this.debug('Mongod instance closed with an non-0 code!');
266271
}
267272
this.debug(`CLOSE: ${code}`);
273+
this.instanceFailed(`Mongod instance closed with code "${code}"`);
268274
}
269275

270276
/**

0 commit comments

Comments
 (0)