mongodb-memory-server icon indicating copy to clipboard operation
mongodb-memory-server copied to clipboard

MongoDB Memory Sever // Unable to Startup and/or Connect

Open Bugs5382 opened this issue 2 years ago • 22 comments

Versions

  • NodeJS: v17.5.0
  • mongodb-memory-server-*: 8.8.0
  • mongodb(the binary version): 5.8.0
  • mongodb(the js package): 2.0.19
  • system: MacOS

package: mongo-memory-server

from package.json:

  "config": {
    "mongodbMemoryServer": {
      "debug": "1"
    }
  },

What is your question?

Hey all. I do not know if this is a bug or not or something else I am doing wrong, but no matter what I do to "start" the MonogMemoryServer it never in the output shows that the "process" has started. I tried every possible varation that I can think of and I ran out of ideas.

I am using this for local development along with unit testing, and not just for unit testing. This would also run "in memory" on my development instance.

Trace

Here are the error messages:

[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node --trace-warnings src`
Debugger listening on ws://127.0.0.1:50295/c43d8872-575a-4a7d-be77-f2898cfaff3a
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
  MongoMS:ResolveConfig Debug Mode Enabled, through package.json +0ms
  MongoMS:MongoMemoryServer create: Called .create() method +0ms
  MongoMS:MongoMemoryServer Mongo[unknown]: start: Called .start() method +1ms
  MongoMS:MongoMemoryServer Mongo[unknown]: _startUpInstance: Called MongoMemoryServer._startUpInstance() method +0ms
  MongoMS:MongoMemoryServer Mongo[unknown]: getStartOptions: forceSamePort: false +0ms
  MongoMS:MongoMemoryServer Mongo[unknown]: _startUpInstance: Creating new MongoDB instance with options: {
  instance: {
    port: 50311,
    dbName: '',
    ip: '0.0.0.0',
    storageEngine: 'wiredTiger',
    replSet: undefined,
    dbPath: '/var/folders/cs/wq9ybm2956x6vjjl2rhk_9jr0000gn/T/mongo-mem--17310-EG5By9TnK4Zd',
    tmpDir: {
      name: '/var/folders/cs/wq9ybm2956x6vjjl2rhk_9jr0000gn/T/mongo-mem--17310-EG5By9TnK4Zd',
      removeCallback: [Function: _cleanupCallback]
    },
    keyfileLocation: undefined,
    args: [ '--enableMajorityReadConcern=false' ],
    auth: false
  },
  binary: undefined,
  spawn: undefined
} +22ms
  MongoMS:MongoInstance create: Called .create() method +0ms
  MongoMS:MongoInstance Mongo[50311]: start +0ms
  MongoMS:MongoBinary getPath +0ms
  MongoMS:DryMongoBinary generateOptions +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Generating Download Path, preferGlobal: "true" +0ms
  MongoMS:DryMongoBinary generatePaths {
  version: '5.0.8',
  downloadDir: '',
  os: { os: 'darwin' },
  platform: 'darwin',
  arch: 'x64',
  systemBinary: ''
} +0ms
  MongoMS:DryMongoBinary getBinaryName +1ms
  MongoMS:DryMongoBinary combineBinaryName +1ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Paths: {
  legacyHomeCache: '/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8',
  modulesCache: '/Users/me/Documents/MYREPO/GIT.nosync/app-name/node_modules/.cache/mongodb-memory-server/mongod-x64-darwin-5.0.8',
  relative: '/Users/me/Documents/MYREPO/GIT.nosync/app-name/mongodb-binaries/mongod-x64-darwin-5.0.8',
  resolveConfig: ''
}  +0ms
  MongoMS:DryMongoBinary generateDownloadPath: no existing binary for version "5.0.8" was found +7ms
  MongoMS:DryMongoBinary generateDownloadPath: using global (preferGlobal) "/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8" +0ms
  MongoMS:MongoBinary getPath: MongoBinary options: {
  "version": "5.0.8",
  "downloadDir": "/Users/me/.cache/mongodb-binaries",
  "os": {
    "os": "darwin"
  },
  "platform": "darwin",
  "arch": "x64",
  "systemBinary": "",
  "checkMD5": false
} +11ms
  MongoMS:DryMongoBinary locateBinary: Trying to locate Binary for version "5.0.8" +1ms
  MongoMS:DryMongoBinary generateOptions +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Generating Download Path, preferGlobal: "true" +0ms
  MongoMS:DryMongoBinary generatePaths {
  version: '5.0.8',
  downloadDir: '/Users/me/.cache/mongodb-binaries',
  os: { os: 'darwin' },
  platform: 'darwin',
  arch: 'x64',
  systemBinary: ''
} +0ms
  MongoMS:DryMongoBinary getBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +1ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generatePaths: resolveConfigValue is not empty +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Paths: {
  legacyHomeCache: '/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8',
  modulesCache: '/Users/me/Documents/MYREPO/GIT.nosync/app-name/node_modules/.cache/mongodb-memory-server/mongod-x64-darwin-5.0.8',
  relative: '/Users/me/Documents/MYREPO/GIT.nosync/app-name/mongodb-binaries/mongod-x64-darwin-5.0.8',
  resolveConfig: '/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8'
}  +0ms
[16:00:42 UTC] DEBUG: Processing Plugins...
[16:00:42 UTC] DEBUG: Processing Routes...
  MongoMS:DryMongoBinary generateDownloadPath: no existing binary for version "5.0.8" was found +400ms
  MongoMS:DryMongoBinary generateDownloadPath: using resolveConfig (DOWNLOAD_DIR) "/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8" +0ms
  MongoMS:DryMongoBinary locateBinary: running generateDownloadPath +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Generating Download Path, preferGlobal: "true" +0ms
  MongoMS:DryMongoBinary generatePaths {
  version: '5.0.8',
  downloadDir: '/Users/me/.cache/mongodb-binaries',
  os: { os: 'darwin' },
  platform: 'darwin',
  arch: 'x64',
  systemBinary: ''
} +0ms
  MongoMS:DryMongoBinary getBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +1ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generatePaths: resolveConfigValue is not empty +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Paths: {
  legacyHomeCache: '/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8',
  modulesCache: '/Users/me/Documents/MYREPO/GIT.nosync/app-name/node_modules/.cache/mongodb-memory-server/mongod-x64-darwin-5.0.8',
  relative: '/Users/me/Documents/MYREPO/GIT.nosync/app-name/mongodb-binaries/mongod-x64-darwin-5.0.8',
  resolveConfig: '/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8'
}  +0ms

I am on MacOSX system and updated to the latest code. I tried everything from different ports to the database name. Below is the javascript code that is excuting the start process.

Code Sample

const MongoClient = require('mongodb').MongoClient
const { MongoMemoryServer } = require('mongodb-memory-server')

// removed irrlevent code

class MongoDatabase extends DatabaseServices {

// removed irrlevent code

  async connectDatabase () {
    let mongoDbUri

    if (this.databaseInfo.localMemory) {

      let _mongo
      do {
        _mongo = await MongoMemoryServer.create({
          instance: {
            ip: '0.0.0.0',
            storageEngine: 'wiredTiger',  // I did this as a test, removed, it still didn't work
            args: ['--enableMajorityReadConcern=false'] // same here, but it didn't make a difference.
          }
        })
      } while(_mongo.getUri() === null)


      // set settings
      const _mongoUri = _mongo.getUri().replace(/\//gi, '').split(':') // NOTE: I never am able to connect and get the getUri method.
      this.databaseInfo.host = _mongoUri[1]
      this.databaseInfo.port = _mongoUri[2]

      mongoDbUri = 'mongodb://' + this.databaseInfo.host + ':' + this.databaseInfo.port
    }

  }
}

Bugs5382 avatar Aug 10 '22 16:08 Bugs5382

mongodb(the binary version): 5.8.0

from what i can tell, no such version exists, nearest valid versions would be: 5.0.x, 6.0.x(rc) also from what i can tell from the log, the default version of 5.0.8 is used

mongodb(the js package): 2.0.19

this does not seem to be correct, because for mongodb 5.x you either need 3.7 or 4.x of the mongodb driver

package: mongo-memory-server

if you are actually using mongo-memory-server (important: not -core), then a binary should have been downloaded in the postinstall, guessing from the provided config not disabling that


from what i can tell, no binary is downloaded / installed and MMS finds that none is around, but the log does not continue to a download (or a message saying RUNTIME_DOWNLOAD is disabled), which means 1 of 2 things: either the log was trimmed OR the process exited before it could get there.

from what i can tell, your code is correct.

hasezoey avatar Aug 10 '22 16:08 hasezoey

mongodb(the binary version): 5.8.0

from what i can tell, no such version exists, nearest valid versions would be: 5.0.x, 6.0.x(rc) also from what i can tell from the log, the default version of 5.0.8 is used

You are right. I am using default. Just 5.0.8. I did not attempt

mongodb(the js package): 2.0.19

this does not seem to be correct, because for mongodb 5.x you either need 3.7 or 4.x of the mongodb driver

    "mongodb": "^4.8.1",

This is what I have in my non-dev dependents.

package: mongo-memory-server

if you are actually using mongo-memory-server (important: not -core), then a binary should have been downloaded in the postinstall, guessing from the provided config not disabling that

from what i can tell, no binary is downloaded / installed and MMS finds that none is around, but the log does not continue to a download (or a message saying RUNTIME_DOWNLOAD is disabled), which means 1 of 2 things: either the log was trimmed OR the process exited before it could get there.

Nothing is trimmed from the log. So.... how to force a POSTINSTALL of the package? I have it for the app only and not globally installed..... I tried just now a "npm uninstall" and then a "npm install" with sudo and still got the same result...

from what i can tell, your code is correct.

Thanks for verification.

Bugs5382 avatar Aug 10 '22 18:08 Bugs5382

how to force a POSTINSTALL of the package? I have it for the app only and not globally installed..... I tried just now a "npm uninstall" and then a "npm install" with sudo and still got the same result...

a postinstall happens when a package is installed or updated, so you need to remove your node_modules folder and try to download again, if it still does not work, then i dont know why its not executing the postinstall

Nothing is trimmed from the log

weird, then that must mean that your application somehow exits / stalls before it can actually get to the decide for a download i also see that you are using nodemon, did you already try running it without? i also can see that a nodejs debugger is attached in the log, did it maybe stop execution at some point before, and did you already try without it? ^ could you maybe provide a log without nodemon and without nodejs inspector?

hasezoey avatar Aug 10 '22 18:08 hasezoey

I'll reset my node_modules.

I'll try without nodemon.

Stand by...

Bugs5382 avatar Aug 10 '22 20:08 Bugs5382

Ok! Good news.

MongoMS:MongoInstance Mongo[49667]: start: Starting Processes +277ms
  MongoMS:MongoInstance Mongo[49667]: _launchMongod: Launching Mongod Process +0ms
  MongoMS:MongoInstance Mongo[49667]: prepareCommandArgs +0ms
  MongoMS:MongoInstance Mongo[49667]: prepareCommandArgs: final argument array:["--port","49667","--dbpath","/var/folders/cs/wq9ybm2956x6vjjl2rhk_9jr0000gn/T/mongo-mem--2455-KUCr5IBXMxPf","--storageEngine","ephemeralForTest","--bind_ip","0.0.0.0","--noauth"] +0ms
  MongoMS:MongoInstance Mongo[49667]: _launchKiller: Launching Killer Process (parent: 2455, child: 2459) +8ms

I got the binary downloaded. Turned out to my my company firewall, and it didn't occur to me since I am on that all the time even at home. Came off, using my home DNS settings and it worked. I'll have to get that fixed for the CI/CD to make sure the firewall doesn't block the download during making the docker image.

Anywho... it never then starts or is not able to launch the getUti() function:

_mongo = await MongoMemoryServer.create({
        instance: {
          ip: '0.0.0.0'
        }
      })

      console.log(_mongo) // never even gets here!

      // set settings
      const _mongoUri = _mongo.getUri() // updated to this for testing

I errors out with the output above and breaks out of my async function and heads back into normal start which fails because the DB is not created with collections, etc. in the end. Next steps?

Bugs5382 avatar Aug 11 '22 20:08 Bugs5382

I got the binary downloaded. Turned out to my my company firewall, and it didn't occur to me since I am on that all the time even at home. Came off, using my home DNS settings and it worked

that is weird, that should not be the problem of not even getting to the download

I errors out with the output above and breaks out of my async function and heads back into normal start which fails because the DB is not created with collections, etc. in the end. Next steps?

looking at the log says that instance never actually gets to launch, it gets to preparing the mongod process arguments but never launches and also never goes after it, which is definitely weird

guessing from the symptoms, something seems to be terminating your promises / execution way to early and / or not logging any errors, if they occur

hasezoey avatar Aug 11 '22 20:08 hasezoey

guessing from the symptoms, something seems to be terminating your promises / execution way to early and / or not logging any errors, if they occur

I am going to put more error handling in the code, than I already have and figure this out.... i look at the mongodb binary..

145720 -rwxr-xr-x  1 me  staff  74606152 Aug  7 22:12 mongod-x64-darwin-4.2.10
**169896 -rwxr-xr-x  1 me  staff  86985472 Aug 11 16:32 mongod-x64-darwin-5.0.8**

Seems to have the right permissions. I had the hardest time with spawn on another bit of code I was working on and I had to kick it out of the "class", but that shouldn't really matter.

Bugs5382 avatar Aug 11 '22 20:08 Bugs5382

 const instance = yield MongoInstance_1.MongoInstance.create(mongodOptions);

Failing here line 223, in MongoMemoryServer.js. I am doing deeper trace, however...

mongodOptions json at this stage:

{
  "instance": {
    "port": 50339,
    "dbName": "",
    "ip": "127.0.0.1",
    "storageEngine": "ephemeralForTest",
    "dbPath": "/var/folders/cs/wq9ybm2956x6vjjl2rhk_9jr0000gn/T/mongo-mem--3134-1sA28ce1uw3e",
    "tmpDir": {
      "name": "/var/folders/cs/wq9ybm2956x6vjjl2rhk_9jr0000gn/T/mongo-mem--3134-1sA28ce1uw3e"
    },
    "auth": false
  }
}

dbName, binary, etc. empty.

Bugs5382 avatar Aug 11 '22 21:08 Bugs5382

dbName, binary, etc. empty.

to be expected

could you maybe provide the full trace + the error?

hasezoey avatar Aug 11 '22 21:08 hasezoey

Still going through the trace... Just wanted to give an update.

Bugs5382 avatar Aug 11 '22 21:08 Bugs5382

Back again. So your system never sent any errors. It does return the "object", so I am wording in my code if there is an issue waiting for it to start because I call that function from another location.... so werid. could it be my version of node? v17 ?

Bugs5382 avatar Aug 15 '22 15:08 Bugs5382

So your system never sent any errors

no, otherwise i would have likely fixed it or at least have been able to reproduce it

could it be my version of node? v17 ?

should not be, though officially MMS only supports the LTS versions + the latest

It does return the "object", so I am wording in my code if there is an issue waiting for it to start because I call that function from another location

i dont quite understand your sentence, aside from that, yes it is weird that it returns with the value way before it is started, though to help more if there is a error, please provide it with the trace and if the log changed, also please post that (fully)


PS: just asking to be sure because its Mac / darwin: are you on a arm systems, when yes do you have rosetta installed & configured?

hasezoey avatar Aug 15 '22 16:08 hasezoey

This is an intel. When I meant object, from your code at the "create" function, it does get to the line of "returning" the MongoMemory object back to who called it. However, in my code with "await" it never sets the object. If I remove the await, I get a "pending" promise which of cause I can not do anything.

Specs are:

  Model Name:	MacBook Pro
  Model Identifier:	MacBookPro16,1
  Processor Name:	8-Core Intel Core i9
  Processor Speed:	2.3 GHz
  Number of Processors:	1
  Total Number of Cores:	8
  L2 Cache (per Core):	256 KB
  L3 Cache:	16 MB
  Hyper-Threading Technology:	Enabled
  Memory:	16 GB
  System Firmware Version:	1731.140.2.0.0 (iBridge: 19.16.16064.0.0,0)
  OS Loader Version:	540.120.3~19
  MongoMS:ResolveConfig Debug Mode Enabled, through package.json +0ms
  MongoMS:MongoMemoryServer create: Called .create() method +0ms
  MongoMS:MongoMemoryServer Mongo[unknown]: start: Called .start() method +0ms
  MongoMS:MongoMemoryServer Mongo[unknown]: _startUpInstance: Called MongoMemoryServer._startUpInstance() method +1ms
  MongoMS:MongoMemoryServer Mongo[unknown]: getStartOptions: forceSamePort: false +0ms
  MongoMS:MongoMemoryServer Mongo[unknown]: _startUpInstance: Creating new MongoDB instance with options: {
  instance: {
    port: 51393,
    dbName: 'app-name-test',
    ip: '127.0.0.1',
    storageEngine: 'ephemeralForTest',
    replSet: undefined,
    dbPath: '/var/folders/cs/wq9ybm2956x6vjjl2rhk_9jr0000gn/T/mongo-mem--2911-Tbxc9485x47v',
    tmpDir: {
      name: '/var/folders/cs/wq9ybm2956x6vjjl2rhk_9jr0000gn/T/mongo-mem--2911-Tbxc9485x47v',
      removeCallback: [Function: _cleanupCallback]
    },
    keyfileLocation: undefined,
    args: undefined,
    auth: false
  },
  binary: undefined,
  spawn: undefined
} +22ms
  MongoMS:MongoInstance create: Called .create() method +0ms
  MongoMS:MongoInstance Mongo[51393]: start +0ms
  MongoMS:MongoBinary getPath +0ms
  MongoMS:DryMongoBinary generateOptions +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Generating Download Path, preferGlobal: "true" +1ms
  MongoMS:DryMongoBinary generatePaths {
  version: '5.0.8',
  downloadDir: '',
  os: { os: 'darwin' },
  platform: 'darwin',
  arch: 'x64',
  systemBinary: ''
} +0ms
  MongoMS:DryMongoBinary getBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +1ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Paths: {
  legacyHomeCache: '/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8',
  modulesCache: '/Users/me/Documents/COPMANY/GIT.nosync/app-name/node_modules/.cache/mongodb-memory-server/mongod-x64-darwin-5.0.8',
  relative: '/Users/me/Documents/COPMANY/GIT.nosync/app-name/mongodb-binaries/mongod-x64-darwin-5.0.8',
  resolveConfig: ''
}  +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Found binary in legacyHomeCache: "/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8" +6ms
  MongoMS:MongoBinary getPath: MongoBinary options: {
  "version": "5.0.8",
  "downloadDir": "/Users/me/.cache/mongodb-binaries",
  "os": {
    "os": "darwin"
  },
  "platform": "darwin",
  "arch": "x64",
  "systemBinary": "",
  "checkMD5": false
} +8ms
  MongoMS:DryMongoBinary locateBinary: Trying to locate Binary for version "5.0.8" +0ms
  MongoMS:DryMongoBinary generateOptions +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Generating Download Path, preferGlobal: "true" +0ms
  MongoMS:DryMongoBinary generatePaths {
  version: '5.0.8',
  downloadDir: '/Users/me/.cache/mongodb-binaries',
  os: { os: 'darwin' },
  platform: 'darwin',
  arch: 'x64',
  systemBinary: ''
} +1ms
  MongoMS:DryMongoBinary getBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generatePaths: resolveConfigValue is not empty +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Paths: {
  legacyHomeCache: '/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8',
  modulesCache: '/Users/me/Documents/COPMANY/GIT.nosync/app-name/node_modules/.cache/mongodb-memory-server/mongod-x64-darwin-5.0.8',
  relative: '/Users/me/Documents/COPMANY/GIT.nosync/app-name/mongodb-binaries/mongod-x64-darwin-5.0.8',
  resolveConfig: '/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8'
}  +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Found binary in resolveConfig (DOWNLOAD_DIR): "/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8" +1ms
  MongoMS:DryMongoBinary locateBinary: running generateDownloadPath +1ms
  MongoMS:DryMongoBinary generateDownloadPath: Generating Download Path, preferGlobal: "true" +0ms
  MongoMS:DryMongoBinary generatePaths {
  version: '5.0.8',
  downloadDir: '/Users/me/.cache/mongodb-binaries',
  os: { os: 'darwin' },
  platform: 'darwin',
  arch: 'x64',
  systemBinary: ''
} +0ms
  MongoMS:DryMongoBinary getBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generatePaths: resolveConfigValue is not empty +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Paths: {
  legacyHomeCache: '/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8',
  modulesCache: '/Users/me/Documents/COPMANY/GIT.nosync/app-name/node_modules/.cache/mongodb-memory-server/mongod-x64-darwin-5.0.8',
  relative: '/Users/me/Documents/COPMANY/GIT.nosync/app-name/mongodb-binaries/mongod-x64-darwin-5.0.8',
  resolveConfig: '/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8'
}  +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Found binary in resolveConfig (DOWNLOAD_DIR): "/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8" +2ms
  MongoMS:DryMongoBinary locateBinary: found binary at "/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8" +0ms
  MongoMS:MongoBinary getPath: Mongod binary path: "/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8" +5ms
[16:35:38 UTC] DEBUG: Processing Plugins...
[16:35:38 UTC] DEBUG: Processing Routes...
  MongoMS:MongoInstance Mongo[51393]: start: Starting Processes +406ms
  MongoMS:MongoInstance Mongo[51393]: _launchMongod: Launching Mongod Process +0ms
  MongoMS:MongoInstance Mongo[51393]: prepareCommandArgs +0ms
  MongoMS:MongoInstance Mongo[51393]: prepareCommandArgs: final argument array:["--port","51393","--dbpath","/var/folders/cs/wq9ybm2956x6vjjl2rhk_9jr0000gn/T/mongo-mem--2911-Tbxc9485x47v","--storageEngine","ephemeralForTest","--bind_ip","127.0.0.1","--noauth"] +0ms
  MongoMS:MongoInstance Mongo[51393]: _launchKiller: Launching Killer Process (parent: 2911, child: 2948) +8ms

Bugs5382 avatar Aug 15 '22 16:08 Bugs5382

seeing another log, i really have no clue why this is happening or how to fix this (because i cannot reproduce it or manually investigate the target)

the only 2 things i think could change something would be:

  • try to change the nodejs version
  • maybe wait until MMS ships with a higher tsconfig-target (which would remove some boilerplate polyfills / backwards-compat code structure) (or manually try this if you know how to)

hasezoey avatar Aug 15 '22 17:08 hasezoey

Yeah. I am not using TS in my project. It's fully CommonJS. Using Fustily as the framework, which does support TS, but this first pass of my code I am keeping in CommonJS and then moving to TS later down the line.

  • maybe wait until MMS ships with a higher tsconfig-target (which would remove some boilerplate polyfills / backwards-compat code structure) (or manually try this if you know how to)

Not sure how to do this... sorry. Hardly ever worked with TS before but starting to learn to convert!

Bugs5382 avatar Aug 15 '22 17:08 Bugs5382

I got something finally!

The process did start. In a "debugger" mode with JetBrains IDE, the mongo spawn process was not being "killed" correctly. I am of course using debugger mode to step through my code and if there is a problem, it exits, but it should kill the process of this spawn because node itself it not running.

The other issue from my code... (it was stupid) i split the getUri and replace into different lines. I don't think the getUri supports chaining of events.

mongo_killer: parentPid not alive
mongo_killer.js:45mongo_killer: couldnt kill child: 
Error: kill ESRCH at process.kill (node:internal/process/per_thread:220:13) at check (/Users/me/Documents/COMPANY/GIT.nosync/app-name/node_modules/mongodb-memory-server-core/scripts/mongo_killer.js:43:15) at Object.<anonymous> (/Users/me/Documents/COMPANY/GIT.nosync/app-name/node_modules/mongodb-memory-server-core/scripts/mongo_killer.js:67:1) at Module._compile (node:internal/modules/cjs/loader:1097:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10) at Module.load (node:internal/modules/cjs/loader:975:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) at node:internal/main/run_main_module:17:47 {errno: -3, code: "ESRCH", syscall: "kill", stack: "Error: kill ESRCH\n at process.kill (node:intern…)\n at node:internal/main/run_main_module:17:47", message: "kill ESRCH"}
errno = -3
code = "ESRCH"
syscall = "kill"
stack = "Error: kill ESRCH\n at process.kill (node:internal/process/per_thread:220:13)\n at check (/Users/me/Documents/COMPANY/GIT.nosync/app-name/node_modules/mongodb-memory-server-core/scripts/mongo_killer.js:43:15)\n at Object.<anonymous> (/Users/me/Documents/COMPANY/GIT.nosync/app-name/node_modules/mongodb-memory-server-core/scripts/mongo_killer.js:67:1)\n at Module._compile (node:internal/modules/cjs/loader:1097:14)\n at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10)\n at Module.load (node:internal/modules/cjs/loader:975:32)\n at Function.Module._load (node:internal/modules/cjs/loader:822:12)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)\n at node:internal/main/run_main_module:17:47"
message = "kill ESRCH"
[[Prototype]] = Object

So when I run it once, it started, maybe not because of code, but then when I tried it again, it said it was already started. I had to go into my process and then

Bugs5382 avatar Aug 15 '22 18:08 Bugs5382

So it's hit or miss if the system "starts" up and returns an object in time either without debugging or no debugging. I even went through the open process to see if anything is stalling. I usually have to restart the IDE in order for it to work and then again, it's off and on.

Bugs5382 avatar Aug 15 '22 21:08 Bugs5382

I don't think the getUri supports chaining of events.

at least since getUri was changed to be sync (instead of async), it is possible to chain, because it will basically be a string, like const yourUri = instance.getUri().replace("s", "") (some random replace)

The process did start. In a "debugger" mode with JetBrains IDE, the mongo spawn process was not being "killed" correctly. I am of course using debugger mode to step through my code and if there is a problem, it exits, but it should kill the process of this spawn because node itself it not running.

i dont know if the debugger is interfering in this case, but from what i could tell from the logs, it seems like nodejs is not properly reporting the childprocess error, because there are 3 ways it could fail and seemingly none are used:

  • spawn throws (like throw new Error())
  • spawn returns a childprocess object and emits a error event
  • spawn returns undefined (and also childprocess.pid being undefined) and MMS will error right as the next step (see this code)

code = "ESRCH"

just as a note (i had too look this up), this error basically means Error Search pid, or said differently No such pid (/group) found to kill

the mongo spawn process was not being "killed" correctly.

no i dont think so, because from what i can tell, it never actually started, and the only logs (and error) you see are from the mongo_killer script (a backup script in case the handling nodejs process exits without notice to stop the running mongod server, TL;DR: it kills the mongod process if the parent is not alive anymore)


i still dont know what is happening, the only thing that could maybe give more insight is a log of the childprocess, could you add console.log("childprocess", childProcess) to MongoInstance.js at between line 233-234 (compiled output) and provide the output this logs?

hasezoey avatar Aug 16 '22 09:08 hasezoey

Hi, if I get it correctly, the error "Error: Instance Exited before being ready and without throwing an error!" can be explained by Mongo binary not being downloaded on "mongodb-memory-server" postinstall? So the child process "mongodb" cannot run?

eric-burel avatar Sep 15 '22 08:09 eric-burel

Hi, if I get it correctly, the error "Error: Instance Exited before being ready and without throwing an error!" can be explained by Mongo binary not being downloaded on "mongodb-memory-server" postinstall? So the child process "mongodb" cannot run?

depends on the issue, as for Error: Instance Exited before being ready and without throwing an error! this means that some error happened, but did not get populated up to where it should be thrown, so the actual error can only be seen when having debug log on

hasezoey avatar Sep 15 '22 08:09 hasezoey

Here's a pastebin of the debug logs if that can be of any help: https://pastebin.com/muSaEavD I will dig them more thoroughly and edit this message if needed

Edit: smells like we have a culprit, given that I hit this error on Ubuntu 22 before that: https://askubuntu.com/questions/1403778/upgrading-to-ubuntu-22-04-causes-libcrypto-errors-apt-dpkg-broken

  MongoMS:MongoInstance Mongo[41327]: stderrHandler: ""/home/eric-burel/.cache/mongodb-binaries/mongod-x64-ubuntu-5.0.8: /lib/x86_64-linux-gnu/libssl.so.1.1: version `OPENSSL_1_1_1' not found (required by /home/eric-burel/.cache/mongodb-binaries/mongod-x64-ubuntu-5.0.8)"" +4ms

Edit2: possible fix here: https://askubuntu.com/questions/1403619/mongodb-install-fails-on-ubuntu-22-04-depends-on-libssl1-1-but-it-is-not-insta In particular this answer with manual downalod: https://askubuntu.com/a/1410366/966818

See https://www.mongodb.com/community/forums/t/installing-mongodb-over-ubuntu-22-04/159931/7

Mongo is simply not officially supported in Ubuntu 22 yet. If still using Ubuntu 20, do not upgrade until this is sorted out, as those fixes are not great in terms of security (Ubuntu 22 uses an higher version of libssl).

eric-burel avatar Sep 15 '22 08:09 eric-burel

Here's a pastebin of the debug logs if that can be of any help: https://pastebin.com/muSaEavD I will dig them more thoroughly and edit this message if needed

your issue according to the logs is:

/home/eric-burel/.cache/mongodb-binaries/mongod-x64-ubuntu-5.0.8: /lib/x86_64-linux-gnu/libssl.so.1.1: version OPENSSL_1_1_1' not found (required by /home/eric-burel/.cache/mongodb-binaries/mongod-x64-ubuntu-5.0.8)`

this means you are missing a OPENSSL library

hasezoey avatar Sep 15 '22 08:09 hasezoey

ubuntu 22.04 (jammy) moved from openssl 1.1.1f-1ubuntu2.16 to openssl 3.0.2-0ubuntu1.7 . While the mongodb downloads page doesnt have a mongodb binary for jammy, their apt repo does have a version specifically for jammy that doesnt need openssl 1.1.1f, located at https://repo.mongodb.org/apt/ubuntu/dists/jammy/mongodb-org/6.0/multiverse/binary-amd64. So, for mongodb-memory-server to work on jammy, we'll need to extract the binary from the .deb package.

I figured this out by comparingdpkg -l | grep " openssl " with the circleci nodejs images: docker run -it cimg/node:16.17.0 vs docker run -it cimg/node:16.18.1 (both docker images are based on ubuntu jammy, just at different moments in time), and ldd ~/.cache/mongodb-memory-server/mongod-x64-ubuntu-6.0.3 vs running ldd on the binary extracted from the above deb

10kc-emilyk avatar Jan 04 '23 04:01 10kc-emilyk

closing because issue is stale and has gone slightly off-topic, if this issue should be encountered again feel free to post here (as long as the used mongodb-memory-server version is below 9.0)

hasezoey avatar Jun 09 '23 12:06 hasezoey