knex icon indicating copy to clipboard operation
knex copied to clipboard

Cannot read properties of undefined

Open tsm2107 opened this issue 1 year ago • 4 comments

Environment

Database: MySQL OS: Windows Node.js v20.12.1

Bug

TypeError: Cannot read properties of undefined

When an application loses its connection to the database, the application crashes with the error TypeError: Cannot read properties of undefined (reading '__knexUid')

#Fix \knex\lib\client.js:344:58 connection.__knexUid to connection?.__knexUid

tsm2107 avatar Apr 03 '24 18:04 tsm2107

Please provide reproductive repo

rluvaton avatar Apr 04 '24 05:04 rluvaton

Just got the same in our production env.

Please provide reproductive repo

That's impossible from my end; ours happens under extremely high loads before it crashes and it's a database with 500GB of RAM. Yes, RAM.

I can't replicate that kind of load even if I tried.

nicholaswmin avatar Apr 24 '24 13:04 nicholaswmin

We also see this, both in production and test environments. And it's not just Windows.

Challenging to replicate though.

TrueWill avatar Sep 11 '24 22:09 TrueWill

Running into this.

Here's some more info on my use case.

It's a busy postgres database. I suspect I'm getting timeouts or even disconnects because the server is short on resources.

We are streaming results back from it.

This is the full stack trace -

TypeError: Cannot read properties of undefined (reading '__knexUid')
    at Client_PG.releaseConnection (/app/node_modules/knex/lib/client.js:344:58)
    at Transform.<anonymous> (/app/node_modules/knex/lib/execution/runner.js:72:19)
    at Transform.emit (node:events:529:35)
    at emitCloseNT (node:internal/streams/destroy:132:10)
    at emitErrorCloseNT (node:internal/streams/destroy:117:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

As you can see, the error is form the stream method, which invokes releaseConnection where its this.connection is undefined

amircodota avatar Jan 04 '25 12:01 amircodota