Skip to content

Pool timeout causes connections to stay open after tests end #46

Description

@slifty

I'm seeing the following when I run my test suite, which uses a tinypg-managed db connection

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 --detectOpenHandles to find leaks. Active timers can also cause this, ensure that .unref() was called on them.

When I diagnose with --detectOpenHandles I get more detail:

Jest has detected the following 1 open handle potentially keeping Jest from exiting:

  ●  Timeout

      47 | 		);
      48 |
    > 49 | 		const result = await db.sql<JsonResultSet<T>>(queryName, queryParameters);
         | 		                        ^
      50 | 		const {
      51 | 			rows: [wrappedObject],
      52 | 		} = result;

      at node_modules/tinypg/src/tiny.ts:377:10
      at TinyPg.<anonymous> (node_modules/tinypg/src/tiny.ts:366:41)
      at node_modules/tinypg/dist/tiny.js:8:71
      at __awaiter (node_modules/tinypg/dist/tiny.js:4:12)
      at TinyPg.performDbCall (node_modules/tinypg/dist/tiny.js:248:16)
      at TinyPg.<anonymous> (node_modules/tinypg/src/tiny.ts:115:22)
      at node_modules/tinypg/dist/tiny.js:8:71
      at __awaiter (node_modules/tinypg/dist/tiny.js:4:12)
      at node_modules/tinypg/src/tiny.ts:106:84
      at Object.<anonymous> (node_modules/tinypg/src/util.ts:19:14)
      at node_modules/tinypg/dist/util.js:8:71
      at __awaiter (node_modules/tinypg/dist/util.js:4:12)
      at Object.stackTraceAccessor (node_modules/tinypg/dist/util.js:27:12)
      at TinyPg.sql (node_modules/tinypg/src/tiny.ts:106:19)
      at src/database/operations/generators/generateLoadItemOperation.ts:49:27
      at Object.<anonymous> (src/database/operations/sources/__test__/loadSystemSource.int.test.ts:11:46)

I think the issue are the timeouts in this block:

tinypg/src/tiny.ts

Lines 373 to 377 in 1632b40

setTimeout(checkForConnection, 500)
}
}
setTimeout(checkForConnection, 500)

It looks like if we add .unref() to the end of the timeout we keep the intended tinypg behavior without causing the test worker issues. I'll try this out an if it works open a PR!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions