Open handle keeping Jest from exiting
See original GitHub issueDescribe the bug I have been trying to use keyv on a Jest unit test. The test runs but Jest complains in the end:
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● TLSWRAP
5 | export class Cache {
6 |
> 7 | private client = new Keyv(process.env.REDIS_CONNECTION_STRING);
I have tried all sorts of approaches to “close” the handle. By calling keyv.disconnect(), by calling keyv.redis.quit(), but I keep getting errors saying the connection is already closed.
/Users/rafasiqueira/Work/etips-api/node_modules/ioredis/built/redis/event_handler.js:182
self.flushQueue(new Error(utils_1.CONNECTION_CLOSED_ERROR_MSG));
^
Error: Connection is closed.
at close (/Users/rafasiqueira/Work/etips-api/node_modules/ioredis/built/redis/event_handler.js:182:25)
at TLSSocket.<anonymous> (/Users/rafasiqueira/Work/etips-api/node_modules/ioredis/built/redis/event_handler.js:149:20)
at Object.onceWrapper (node:events:652:26)
at TLSSocket.emit (node:events:549:35)
at node:net:747:14
at TCP.done (node:_tls_wrap:582:7)
To Reproduce
let client = new Keyv(process.env.REDIS_CONNECTION_STRING);
private keyAdapter = new KeyvAdapter(this.client);
public faultTolerantCache = new ErrorsAreMissesCache(this.keyAdapter);
const serverOptions: ApolloServerExpressConfig = {
schema: subgraphSchema,
dataSources,
context,
plugins: [ApolloServerPluginInlineTraceDisabled()],
cache: faultTolerantCache
let server: ApolloServer;
beforeAll(() => {
server = new ApolloServer(serverOptions);
});
afterAll((done) => {
client.disconnect().then(() => done());
});
it('fetches mtdsg action', (done) => {
server.executeOperation({
query: GET_ACTION,
variables: { id: '080000028047f4a3' }
})
.then((result) => {
expect(result.errors).toBeUndefined();
done();
});
});
**Expected behavior**
The test should pass and Jest should exit.
Issue Analytics
- State:
- Created a year ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Jest has detected the following 1 open handle potentially ...
The server isn't being closed and remains open after the test. You need to create a variable to reference the instance and close...
Read more >Open handle keeps Jest from exiting ( TCPSERVERWRAP)
I was facing the same issue and it turned out the MySQL connection stays active after finish the test and prevent Jest from...
Read more >Jest has detected the following 1 open handle ... - Temporal
Hi, im using Jest to test Temporal workflows/activities as wrote in ... the following 1 open handle potentially keeping Jest from exiting.
Read more >How to fix err Jest has detected the following 3 open handles ...
Coding example for the question How to fix err Jest has detected the following 3 open handles potentially keeping Jest from exiting-node.js.
Read more >Jsforce connection leaves open handle when unit testing with ...
Jest has detected the following 1 open handle potentially keeping Jest from exiting: ○ TCPWRAP 11 | let conn = new jsforce.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @rafagsiqueira - thanks and we are looking into this.
Sorry, I ended up removing the cache from my unit tests.