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

"MongoMemoryReplSet" in "jest" gives open handle error #213

Closed
j opened this issue Aug 12, 2019 · 20 comments
Closed

"MongoMemoryReplSet" in "jest" gives open handle error #213

j opened this issue Aug 12, 2019 · 20 comments
Labels
bug Needs More Information stale This Issue is outdated and will likely be closed if no further comments are given

Comments

@j
Copy link

j commented Aug 12, 2019

If I close the client & await replSet.stop(), jest spits out an error:

Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.

If I don't use a replset, then it works.

describe('MyTests', () => {
  let replSet: MongoMemoryReplSet;
  let client: MongoClient;

  beforeAll(async () => {
    replSet = new MongoMemoryReplSet({
      binary: {
        version: '4.0.5'
      },
      instanceOpts: [{
        storageEngine: 'wiredTiger'
      }],
      autoStart: true,
      debug: true
    });

    await replSet.waitUntilRunning();

    // ... connect to client, etc
  });

  afterAll(async () => {
    await client.close();
    await replSet.stop();
  });

  // ...
});

If I replace the above with just a single mongo server and stop it, it works.

@hasezoey
Copy link
Collaborator

@j does this still happen on later versions of this package? and could you provide your used mongodb version?

@hasezoey hasezoey added the stale This Issue is outdated and will likely be closed if no further comments are given label Dec 27, 2019
@hasezoey hasezoey changed the title MongoMemoryReplSet in jest gives open handle error "MongoMemoryReplSet" in "jest" gives open handle error Sep 7, 2020
@hasezoey
Copy link
Collaborator

hasezoey commented Sep 7, 2020

i think #166 is related

@hasezoey
Copy link
Collaborator

hasezoey commented Sep 8, 2020

closing in favor of #166 and #300

@hasezoey hasezoey closed this as completed Sep 8, 2020
@abishek28007
Copy link

abishek28007 commented Nov 9, 2020

@j does this still happen on later versions of this package? and could you provide your used mongodb version?

Which later version, I am facing this in package version 6.9.2,

@abishek28007
Copy link

An Process didnt exit with signal "SIGINT" within 10 seconds, using "SIGKILL"!
Enable debug logs for more information

  at Timeout._onTimeout (node_modules/mongodb-memory-server-core/src/util/MongoInstance.ts:162:21)

@hasezoey
Copy link
Collaborator

hasezoey commented Nov 9, 2020

@abishek28007 your "warning" has nothing to do with this issue, it comes when MongoInstance.stop is called where SIGINT is tried first, 10 seconds waiting and this warning comes up and SIGKILL is used
-> and then if the process exists, the promise resolves - so it has nothing to do with jest open handle error

@abishek28007
Copy link

@hasezoey I posted the underlining log

Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
  console.warn
    An Process didnt exit with signal "SIGINT" within 10 seconds, using "SIGKILL"!
    Enable debug logs for more information

      at Timeout._onTimeout (node_modules/mongodb-memory-server-core/src/util/MongoInstance.ts:162:21)

@hasezoey
Copy link
Collaborator

hasezoey commented Nov 9, 2020

@abishek28007 this seems like you didnt await an .stop, did you check that already?

@abishek28007
Copy link

yup using await replSet.stop() in afterall

@abishek28007
Copy link

works fine for await mongod.stop() created with MongoMemoryServer

@hasezoey
Copy link
Collaborator

hasezoey commented Nov 9, 2020

@abishek28007 this case is known and already fixed in 7.0.0 (beta), will not be fixed in an 6.x release (because it requires refactor of some code)
-> i mean the warning, it shouldnt hinder jest from exiting if awaited

@abishek28007
Copy link

@hasezoey which beta version I updated to "mongodb-memory-server": "^7.0.0-beta.1" still facing this issue

@hasezoey
Copy link
Collaborator

hasezoey commented Nov 9, 2020

@abishek28007 every beta below 7 is an broken build (build process was not called directly), so use that at lowest if using beta - this warning (for replsets) got fixed in 6 (but like i said, broken build)

-> because the beta is still ongoing, there are no deprecation warnings yet on an 6.x release

@abishek28007
Copy link

@hasezoey not sure what was added in beta 7 but getting "instanceInfo" is undefined for const uri = await mongod.getUri(); for MongoMemoryServer

@abishek28007
Copy link

@hasezoey error for MongoMemoryReplSet

 `State is not "running" or "init" - cannot wait on something that dosnt start

  at MongoMemoryReplSet.<anonymous> (node_modules/mongodb-memory-server-core/src/MongoMemoryReplSet.ts:417:15)
  at fulfilled (node_modules/mongodb-memory-server-core/node_modules/tslib/tslib.js:111:62)`

@hasezoey
Copy link
Collaborator

hasezoey commented Nov 9, 2020

@abishek28007 like i said, there isnt an "smooth" transition release yet, please read the changelog on what changed

not sure what was added in beta 7 but getting "instanceInfo" is undefined for const uri = await mongod.getUri(); for MongoMemoryServer

this is because getUri is in 7.0.0 not async anymore and dosnt wait for the server start anymore


aside from this, autoStart got removed, so you need to either manually call .start, or use the static method .create

@jverce
Copy link

jverce commented Dec 3, 2020

Hello,
If I understood correctly, the workaround for now is to just stop calling replSet.stop() basically?

Thanks!

P.S.: I'm also experiencing this in Mocha, not just Jest.

@hasezoey
Copy link
Collaborator

hasezoey commented Dec 4, 2020

@jverce no, basically the "smooth shutdown" is just not released yet, so either wait for it to use SIGKILL, or try to use 7.0 beta

@JonesWest
Copy link

JonesWest commented Dec 6, 2020

I am experiencing the same issue. Tried to update to ^7.0.0-beta.1, and changed to:

	/**
	 * Connect to the in-memory database.
	 */
	async connect() {
		this.mongodReplSet = await MongoMemoryReplSet.create({
			replSet: { storageEngine: 'wiredTiger' },
		});
		await this.mongodReplSet.waitUntilRunning();
		const uri = await this.mongodReplSet.getUri();

		const mongooseOpts = {
			useNewUrlParser: true,
			useUnifiedTopology: true,
			useCreateIndex: true,
		};

		await connect(uri, mongooseOpts);
	}

But the database never comes online. An exception is catched inside the tmp module saying that /var/folders/qm/25v7s8kx2rb1gm5pgdphv2mw0000gn/T/mongo-mem--72763-iHJC5AJDHcfT does not exist.

@hasezoey do you have any suggestions?

I have a lot of testcases and running all of them takes quite a while, when I need to wait the 10 sec for the SIGKILL :-)

@hasezoey
Copy link
Collaborator

hasezoey commented Dec 6, 2020

@JonasWestAlro please open an new issue, with all the information required

PS: all 7.0.0 betas below .7 were broken, and if possible always use the latest beta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Needs More Information stale This Issue is outdated and will likely be closed if no further comments are given
Projects
None yet
Development

No branches or pull requests

5 participants