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.

Open handle keeping Jest from exiting

See original GitHub issue

Describe 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:closed
  • Created a year ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jaredwraycommented, Jul 15, 2022

Hi @rafagsiqueira - thanks and we are looking into this.

0reactions
rafagsiqueiracommented, Aug 2, 2022

Sorry, I ended up removing the cache from my unit tests.

Read more comments on GitHub >

github_iconTop 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 >

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