Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting the instance failed... top: "instanceInfo" is not defined (never ran?) +0ms #617

Closed
romerodiesan opened this issue Mar 17, 2022 · 4 comments
Labels

Comments

@romerodiesan
Copy link

Versions

  • NodeJS: 16.14.1
  • mongodb-memory-server-*: 8.4.1
  • mongodb(the binary version): 4.4.6
  • mongodb(the js package): 5>x
  • mongoose: 6.2.7
  • system: MacOS Monterey 12.3

package: mongo-memory-server

What is your question?

I am trying to make some test (with jest and supertest) to an API with express and MongoDB (using mongoose). I make the following global setup:

import { MongoMemoryServer } from 'mongodb-memory-server';
import mongoose from 'mongoose';
// import { app } from '../app';
 
let mongo: any;
beforeAll(async () => {
  process.env.JWT_KEY = 'asdfasdf';
 
  mongo = await MongoMemoryServer.create();
  const mongoUri = mongo.getUri();
  await mongoose.connect(mongoUri);
});
 
beforeEach(async () => {
  const collections = await mongoose.connection.db.collections();
 
  for (const collection of collections) {
    await collection.deleteMany({});
  }
});
 
afterAll(async () => {
  await mongo.stop();
  await mongoose.disconnect();
});

As you can see, the idea is to keep the MongoDB connection flowing until the tests finish running. But I got this error:

console.warn
Starting the instance failed, enable debug for more information

So I activated the debugger and discovered that it is about this error:

MongoMS:MongoMemoryServer Mongo[unknown]: stop: Called .stop() method +14ms
MongoMS:MongoMemoryServer Mongo[unknown]: stop: "instanceInfo" is not defined (never ran?) +0ms

Anyone has an idea of what this is happend?

@hasezoey
Copy link
Member

hasezoey commented Mar 17, 2022

So I activated the debugger and discovered that it is about this error:

please provide more of the debug log, the message "instanceInfo" is not defined (never ran?) is just a assert before returning from .start to make sure the value actually exists (also the Called .stop() method is just a insurance that is called after the check, but before the "error" message to ensure that no leak instance of mongod is running)

but yes, there should be some other error from where else (if possible)

@romerodiesan
Copy link
Author

romerodiesan commented Mar 17, 2022

@hasezoey

This is the complete error:


  MongoMS:ResolveConfig Debug Mode Enabled, through Environment Variable +0ms
  MongoMS:ResolveConfig findPackageJson: Found package.json at "/Users/diesanromero/Documents/Projects/Every Benefits/auth/package.json" +1ms
  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 +0ms
  MongoMS:MongoMemoryServer Mongo[unknown]: getStartOptions: forceSamePort: false +0ms
  MongoMS:MongoMemoryServer Mongo[unknown]: _startUpInstance: Creating new MongoDB instance with options: {
  instance: {
    port: 53833,
    dbName: '',
    ip: '127.0.0.1',
    storageEngine: 'ephemeralForTest',
    replSet: undefined,
    dbPath: '/var/folders/nl/y79qvc8x2z3c9xz95tnplszm0000gn/T/mongo-mem--13022-Hp5kIJL8lhb9',
    tmpDir: {
      name: '/var/folders/nl/y79qvc8x2z3c9xz95tnplszm0000gn/T/mongo-mem--13022-Hp5kIJL8lhb9',
      removeCallback: [Function: _cleanupCallback]
    },
    args: undefined,
    auth: undefined
  },
  binary: undefined,
  spawn: undefined
} +2ms
  MongoMS:MongoInstance create: Called .create() method +0ms
  MongoMS:MongoInstance Mongo[53833]: start +1ms
  MongoMS:MongoBinary getPath +0ms
  MongoMS:DryMongoBinary generateOptions +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Generating Download Path, preferGlobal: "true" +0ms
  MongoMS:DryMongoBinary generatePaths {
  version: '5.0.3',
  downloadDir: '',
  os: { os: 'darwin' },
  arch: 'arm64',
  systemBinary: ''
} +0ms
  MongoMS:DryMongoBinary getBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +1ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Paths: {
  legacyHomeCache: '/Users/diesanromero/.cache/mongodb-binaries/mongod-arm64-darwin-5.0.3',
  modulesCache: '/Users/diesanromero/Documents/Projects/Every Benefits/auth/node_modules/.cache/mongodb-memory-server/mongod-arm64-darwin-5.0.3',
  relative: '/Users/diesanromero/Documents/Projects/Every Benefits/auth/mongodb-binaries/mongod-arm64-darwin-5.0.3',
  resolveConfig: ''
}  +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Found binary in legacyHomeCache: "/Users/diesanromero/.cache/mongodb-binaries/mongod-arm64-darwin-5.0.3" +3ms
  MongoMS:DryMongoBinary generateOptions: ARCHIVE_NAME or DOWNLOAD_URL defined, generating options based on that (input: "https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.4.6.tgz") +0ms
  MongoMS:DryMongoBinary parseArchiveNameRegex (input: "https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.4.6.tgz") +0ms
  MongoMS:MongoBinary getPath: MongoBinary options: {
  "version": "4.4.6",
  "downloadDir": "/Users/diesanromero/.cache/mongodb-binaries",
  "os": {
    "os": "macos"
  },
  "arch": "x86_64",
  "systemBinary": "",
  "platform": "darwin",
  "checkMD5": false
} +4ms
  MongoMS:DryMongoBinary locateBinary: Trying to locate Binary for version "4.4.6" +0ms
  MongoMS:DryMongoBinary generateOptions +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Generating Download Path, preferGlobal: "true" +0ms
  MongoMS:DryMongoBinary generatePaths {
  version: '4.4.6',
  downloadDir: '/Users/diesanromero/.cache/mongodb-binaries',
  os: { os: 'macos' },
  arch: 'x86_64',
  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/diesanromero/.cache/mongodb-binaries/mongod-x86_64-macos-4.4.6',
  modulesCache: '/Users/diesanromero/Documents/Projects/Every Benefits/auth/node_modules/.cache/mongodb-memory-server/mongod-x86_64-macos-4.4.6',
  relative: '/Users/diesanromero/Documents/Projects/Every Benefits/auth/mongodb-binaries/mongod-x86_64-macos-4.4.6',
  resolveConfig: '/Users/diesanromero/.cache/mongodb-binaries/mongod-x86_64-macos-4.4.6'
}  +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Found binary in resolveConfig (DOWNLOAD_DIR): "/Users/diesanromero/.cache/mongodb-binaries/mongod-x86_64-macos-4.4.6" +0ms
  MongoMS:DryMongoBinary generateOptions: ARCHIVE_NAME or DOWNLOAD_URL defined, generating options based on that (input: "https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.4.6.tgz") +1ms
  MongoMS:DryMongoBinary parseArchiveNameRegex (input: "https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.4.6.tgz") +0ms
  MongoMS:DryMongoBinary locateBinary: running generateDownloadPath +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Generating Download Path, preferGlobal: "true" +0ms
  MongoMS:DryMongoBinary generatePaths {
  version: '4.4.6',
  downloadDir: '/Users/diesanromero/.cache/mongodb-binaries',
  os: { os: 'macos' },
  arch: 'x86_64',
  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/diesanromero/.cache/mongodb-binaries/mongod-x86_64-macos-4.4.6',
  modulesCache: '/Users/diesanromero/Documents/Projects/Every Benefits/auth/node_modules/.cache/mongodb-memory-server/mongod-x86_64-macos-4.4.6',
  relative: '/Users/diesanromero/Documents/Projects/Every Benefits/auth/mongodb-binaries/mongod-x86_64-macos-4.4.6',
  resolveConfig: '/Users/diesanromero/.cache/mongodb-binaries/mongod-x86_64-macos-4.4.6'
}  +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Found binary in resolveConfig (DOWNLOAD_DIR): "/Users/diesanromero/.cache/mongodb-binaries/mongod-x86_64-macos-4.4.6" +0ms
  MongoMS:DryMongoBinary locateBinary: found binary at "/Users/diesanromero/.cache/mongodb-binaries/mongod-x86_64-macos-4.4.6" +0ms
  MongoMS:MongoBinary getPath: Mongod binary path: "/Users/diesanromero/.cache/mongodb-binaries/mongod-x86_64-macos-4.4.6" +1ms
  MongoMS:MongoInstance Mongo[53833]: start: Starting Processes +5ms
  MongoMS:MongoInstance Mongo[53833]: _launchMongod: Launching Mongod Process +0ms
  MongoMS:MongoInstance Mongo[53833]: prepareCommandArgs +0ms
  MongoMS:MongoInstance Mongo[53833]: prepareCommandArgs: final argument ar
➜  auth git:(test) ✗ npm test

> @everybenefits/[email protected] test
> jest

  MongoMS:ResolveConfig Debug Mode Enabled, through Environment Variable +0ms
  MongoMS:ResolveConfig findPackageJson: Found package.json at "/Users/diesanromero/Documents/Projects/Every Benefits/auth/package.json" +0ms
  MongoMS:ResolveConfig Debug Mode Enabled, through package.json +1ms
  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 +0ms
  MongoMS:MongoMemoryServer Mongo[unknown]: getStartOptions: forceSamePort: false +0ms
  MongoMS:MongoMemoryServer Mongo[unknown]: _startUpInstance: Creating new MongoDB instance with options: {
  instance: {
    port: 53946,
    dbName: '',
    ip: '127.0.0.1',
    storageEngine: 'ephemeralForTest',
    replSet: undefined,
    dbPath: '/var/folders/nl/y79qvc8x2z3c9xz95tnplszm0000gn/T/mongo-mem--13508-A3lPrO7ahfoH',
    tmpDir: {
      name: '/var/folders/nl/y79qvc8x2z3c9xz95tnplszm0000gn/T/mongo-mem--13508-A3lPrO7ahfoH',
      removeCallback: [Function: _cleanupCallback]
    },
    args: undefined,
    auth: undefined
  },
  binary: undefined,
  spawn: undefined
} +2ms
  MongoMS:MongoInstance create: Called .create() method +0ms
  MongoMS:MongoInstance Mongo[53946]: start +1ms
  MongoMS:MongoBinary getPath +0ms
  MongoMS:DryMongoBinary generateOptions +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Generating Download Path, preferGlobal: "true" +0ms
  MongoMS:DryMongoBinary generatePaths {
  version: '5.0.3',
  downloadDir: '',
  os: { os: 'darwin' },
  arch: 'arm64',
  systemBinary: ''
} +0ms
  MongoMS:DryMongoBinary getBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +1ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Paths: {
  legacyHomeCache: '/Users/diesanromero/.cache/mongodb-binaries/mongod-arm64-darwin-5.0.3',
  modulesCache: '/Users/diesanromero/Documents/Projects/Every Benefits/auth/node_modules/.cache/mongodb-memory-server/mongod-arm64-darwin-5.0.3',
  relative: '/Users/diesanromero/Documents/Projects/Every Benefits/auth/mongodb-binaries/mongod-arm64-darwin-5.0.3',
  resolveConfig: ''
}  +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Found binary in legacyHomeCache: "/Users/diesanromero/.cache/mongodb-binaries/mongod-arm64-darwin-5.0.3" +2ms
  MongoMS:DryMongoBinary generateOptions: ARCHIVE_NAME or DOWNLOAD_URL defined, generating options based on that (input: "https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.4.6.tgz") +0ms
  MongoMS:DryMongoBinary parseArchiveNameRegex (input: "https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.4.6.tgz") +1ms
  MongoMS:MongoBinary getPath: MongoBinary options: {
  "version": "4.4.6",
  "downloadDir": "/Users/diesanromero/.cache/mongodb-binaries",
  "os": {
    "os": "macos"
  },
  "arch": "x86_64",
  "systemBinary": "",
  "platform": "darwin",
  "checkMD5": false
} +4ms
  MongoMS:DryMongoBinary locateBinary: Trying to locate Binary for version "4.4.6" +0ms
  MongoMS:DryMongoBinary generateOptions +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Generating Download Path, preferGlobal: "true" +0ms
  MongoMS:DryMongoBinary generatePaths {
  version: '4.4.6',
  downloadDir: '/Users/diesanromero/.cache/mongodb-binaries',
  os: { os: 'macos' },
  arch: 'x86_64',
  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/diesanromero/.cache/mongodb-binaries/mongod-x86_64-macos-4.4.6',
  modulesCache: '/Users/diesanromero/Documents/Projects/Every Benefits/auth/node_modules/.cache/mongodb-memory-server/mongod-x86_64-macos-4.4.6',
  relative: '/Users/diesanromero/Documents/Projects/Every Benefits/auth/mongodb-binaries/mongod-x86_64-macos-4.4.6',
  resolveConfig: '/Users/diesanromero/.cache/mongodb-binaries/mongod-x86_64-macos-4.4.6'
}  +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Found binary in resolveConfig (DOWNLOAD_DIR): "/Users/diesanromero/.cache/mongodb-binaries/mongod-x86_64-macos-4.4.6" +0ms
  MongoMS:DryMongoBinary generateOptions: ARCHIVE_NAME or DOWNLOAD_URL defined, generating options based on that (input: "https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.4.6.tgz") +0ms
  MongoMS:DryMongoBinary parseArchiveNameRegex (input: "https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.4.6.tgz") +0ms
  MongoMS:DryMongoBinary locateBinary: running generateDownloadPath +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Generating Download Path, preferGlobal: "true" +0ms
  MongoMS:DryMongoBinary generatePaths {
  version: '4.4.6',
  downloadDir: '/Users/diesanromero/.cache/mongodb-binaries',
  os: { os: 'macos' },
  arch: 'x86_64',
  systemBinary: ''
} +0ms
  MongoMS:DryMongoBinary getBinaryName +1ms
  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/diesanromero/.cache/mongodb-binaries/mongod-x86_64-macos-4.4.6',
  modulesCache: '/Users/diesanromero/Documents/Projects/Every Benefits/auth/node_modules/.cache/mongodb-memory-server/mongod-x86_64-macos-4.4.6',
  relative: '/Users/diesanromero/Documents/Projects/Every Benefits/auth/mongodb-binaries/mongod-x86_64-macos-4.4.6',
  resolveConfig: '/Users/diesanromero/.cache/mongodb-binaries/mongod-x86_64-macos-4.4.6'
}  +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Found binary in resolveConfig (DOWNLOAD_DIR): "/Users/diesanromero/.cache/mongodb-binaries/mongod-x86_64-macos-4.4.6" +0ms
  MongoMS:DryMongoBinary locateBinary: found binary at "/Users/diesanromero/.cache/mongodb-binaries/mongod-x86_64-macos-4.4.6" +0ms
  MongoMS:MongoBinary getPath: Mongod binary path: "/Users/diesanromero/.cache/mongodb-binaries/mongod-x86_64-macos-4.4.6" +1ms
  MongoMS:MongoInstance Mongo[53946]: start: Starting Processes +5ms
  MongoMS:MongoInstance Mongo[53946]: _launchMongod: Launching Mongod Process +0ms
  MongoMS:MongoInstance Mongo[53946]: prepareCommandArgs +0ms
  MongoMS:MongoInstance Mongo[53946]: prepareCommandArgs: final argument array:["--port","53946","--dbpath","/var/folders/nl/y79qvc8x2z3c9xz95tnplszm0000gn/T/mongo-mem--13508-A3lPrO7ahfoH","--storageEngine","ephemeralForTest","--bind_ip","127.0.0.1","--noauth"] +0ms
  MongoMS:MongoMemoryServer Mongo[unknown]: stop: Called .stop() method +13ms
  MongoMS:MongoMemoryServer Mongo[unknown]: stop: "instanceInfo" is not defined (never ran?) +0ms
 FAIL  src/routes/__test__/signup.test.ts
  ● returns a 201 on successful signup

    spawn Unknown system error -86

      at MongoInstance._launchMongod (node_modules/mongodb-memory-server-core/src/util/MongoInstance.ts:443:31)
      at MongoInstance.<anonymous> (node_modules/mongodb-memory-server-core/src/util/MongoInstance.ts:345:31)
      at fulfilled (node_modules/tslib/tslib.js:114:62)


  ● Test suite failed to run

    TypeError: Cannot read properties of undefined (reading 'stop')

      22 | afterAll(async () => {
      23 |   await mongoose.disconnect();
    > 24 |   await mongo.stop();
         |               ^
      25 | });

      at src/test/setup.ts:24:15
      at fulfilled (src/test/setup.ts:5:58)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        1.343 s, estimated 3 s

@hasezoey
Copy link
Member

thanks for providing the log, i have seen a (probably) unrelated issue in your log, which i have mentioned in #618


from your log i can parse that your are running MacOS with ARM architecture, but just to confirm, you are explicitly trying to run MongoDB Version 4.4.6, right?

also, the real problem here is that mongodb immediately exists with error Unknown system error -86 (probably system could not execute binary), which may be related that the binary is for x86_64 and somehow cannot run on your arm machine, maybe try to delete the binary and try to let it re-download it and check if rosetta (the x86_64 to arm runtime) is working

in your case the mongodb binaries are stored at /Users/diesanromero/.cache/mongodb-binaries/, so maybe try to delete the folder or all the content within

@romerodiesan
Copy link
Author

@romerodiesan Hi, thanks. That solved my error. I delete the folder in order to have a future clean download, and install Rosseta 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants