mariadb-corporation / mariadb-connector-nodejs

MariaDB Connector/Node.js is used to connect applications developed on Node.js to MariaDB and MySQL databases. MariaDB Connector/Node.js is LGPL licensed.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Awaiting for the pool to end returns before the pool ends completely

weg-da opened this issue · comments

commented

When running a jest test (typescript), i am connecting to a mariadb using a pool. The database querys are working fine.
After finishing the tests, the mariadb connection is ended, but still there is an Error.

Awaiting for the pool to end is not ending the pool completely, there seems to be still a process running in the background.

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From test/ddl.view.test.ts.

  at Function.pluginHandler (../.yarn/cache/mariadb-npm-3.1.0-1d9a7a9506-d906ffc915.zip/node_modules/mariadb/lib/cmd/handshake/handshake.js:205:22)
  at Handshake.dispatchAuthSwitchRequest (../.yarn/cache/mariadb-npm-3.1.0-1d9a7a9506-d906ffc915.zip/node_modules/mariadb/lib/cmd/handshake/handshake.js:168:31)
  at Handshake.handshakeResult (../.yarn/cache/mariadb-npm-3.1.0-1d9a7a9506-d906ffc915.zip/node_modules/mariadb/lib/cmd/handshake/handshake.js:93:14)
  at PacketInputStream.receivePacketBasic (../.yarn/cache/mariadb-npm-3.1.0-1d9a7a9506-d906ffc915.zip/node_modules/mariadb/lib/io/packet-input-stream.js:80:9)
  at PacketInputStream.onData (../.yarn/cache/mariadb-npm-3.1.0-1d9a7a9506-d906ffc915.zip/node_modules/mariadb/lib/io/packet-input-stream.js:130:20)

Code used for closing the pool:

afterAll(async () => {
await pool.end()
})

What fixed the problem temporarily:

afterAll(async () => {
await pool.end()
await new Promise((resolve) => {
setTimeout(resolve, 100)
})
})

Some race condition can make that possible : closing pool while pool was in the middle of creating a connection. That is not a problem usually because the connection being created will automatically beeing close a few nanoseconds after, but current implementation for authentication import file, making the error listed above.

This will be corrected in 3.1.2

closing since correction is released