question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ioredis left open handles in Jest

See original GitHub issue

Hello. I can’t resolve the issue with my Jest tests because of ioredis. Recently I started recieving messages after Jest finished all tests:

A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --runInBand --detectOpenHandles to find leaks.

After a few days of struggling I found the module called leaked-handles, installed it and started debugging. And it seems like both redis.quit() and redis.disconnect() not working and connection remains opened after those calls. The error is:

at D:\github\umbress\node_modules\ioredis\built\connectors\StandaloneConnector.js:58:45
tcp stream {
  fd: -1,
  readable: true,
  writable: true,
  address: { address: '127.0.0.1', family: 'IPv4', port: 59823 },
  serverAddr: null
}

I couldn’t find any mentioning of ioredis at Jest repo and viceversa. Is there anything that can be done to close connection properly?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:39
  • Comments:29 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
alanbuenocommented, Aug 10, 2020

+1 with the issue here, had both redis.quit() awaited and redis.disconnect() called but nothing 😕

4reactions
beneatercommented, Jul 24, 2020

I’m having a similar issue. I was able to work around it by continually checking the connection status. If it’s not disconnected, just wait 200ms and check again, etc:

redis.disconnect();
while (redis.status === "connected") {
  await new Promise(r => setTimeout(r, 200));
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js: Jest + redis.quit() but open handle warning persists
It always throws the "Jest has detected the following 1 open handle potentially keeping Jest from exiting:" error when running with ...
Read more >
ioredis causes Jest to not exit after the test run has completed
Jest has detected the following 4 open handles potentially keeping Jest from exiting: ○ Timeout afterEach(async () => redis.flushall()); ...
Read more >
Troubleshooting - Jest
Troubleshooting. Uh oh, something went wrong? Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why​.
Read more >
ioredis - npm
A robust, performance-focused and full-featured Redis client for Node.js.. Latest version: 5.2.4, last published: 2 months ago.
Read more >
Testing everything against the real database in Nodejs ...
From the monolithic to microservices, the testing pulls out all the ... these are the extensions Jest will look for, in left-to-right order...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found