From 209520f124307ab6e8518d78e64a612d6393ac36 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Wed, 22 Jun 2022 21:15:51 +0200 Subject: [PATCH] fix(utils::killProcess): handle case where input could be undefined at runtime somehow, it can come in undefined, so it needs to be handled fixes #666 --- packages/mongodb-memory-server-core/src/util/utils.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/mongodb-memory-server-core/src/util/utils.ts b/packages/mongodb-memory-server-core/src/util/utils.ts index 054e0232a..2cb297229 100644 --- a/packages/mongodb-memory-server-core/src/util/utils.ts +++ b/packages/mongodb-memory-server-core/src/util/utils.ts @@ -99,6 +99,13 @@ export async function killProcess( log(`Mongo[${mongodPort || 'unknown'}] killProcess: ${msg}`); } + // this case can somehow happen, see https://github.com/nodkz/mongodb-memory-server/issues/666 + if (isNullOrUndefined(childprocess)) { + ilog('childprocess was somehow undefined'); + + return; + } + // check if the childProcess (via PID) is still alive (found thanks to https://github.com/nodkz/mongodb-memory-server/issues/411) if (!isAlive(childprocess.pid)) { ilog("given childProcess's PID was not alive anymore");