Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryRunner stale/idle connections issue #4372

Open
michaelndu opened this issue Jun 28, 2019 · 0 comments
Open

QueryRunner stale/idle connections issue #4372

michaelndu opened this issue Jun 28, 2019 · 0 comments

Comments

@michaelndu
Copy link

Issue type:

[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[x] 0.2.11 (or put your version here)

Hello,

We're running a NestJS app using typeorm to read/write data from a mysql (Aurora) instance. We're seeing an issue with what appears to be idle connections being used by the QueryRunner, and we encounter the following error:

QueryFailedError: Connection lost: The server closed the connection.
    at new QueryFailedError (/usr/src/app/node_modules/typeorm/error/QueryFailedError.js:28:28)
    at Query.<anonymous> (/usr/src/app/node_modules/typeorm/driver/mysql/MysqlQueryRunner.js:227:45)
    at Query.<anonymous> (/usr/src/app/node_modules/mysql/lib/Connection.js:502:10)
    at Query._callback (/usr/src/app/node_modules/mysql/lib/Connection.js:468:16)
    at Query.Sequence.end (/usr/src/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24)
    at /usr/src/app/node_modules/mysql/lib/protocol/Protocol.js:396:18
    at Array.forEach (<anonymous>)
    at /usr/src/app/node_modules/mysql/lib/protocol/Protocol.js:395:13
    at process._tickCallback (internal/process/next_tick.js:61:11)

So far we haven't seen this issue when using repository.save or repository.update, we've only seen this from the calls that use a queryBuilder, such as

this.repo.createQueryBuilder('merchant')
      .leftJoinAndSelect('merchant.profile', 'profile')
      ...
      .leftJoinAndSelect('merchant.orderRules', 'orderRules')
      .addOrderBy('orderRules.index');
      .where('merchant.usageReportingScheduleBucket = :bucket', { bucket })
      .andWhere('merchant.billingId is not null')
      .getMany();

I'm wondering if this is potentially a bug where connections are being held open for too long, and only recycled when a connection error is encountered? From my understanding, the QueryRunner is supposed to create and use a dedicated connection, but that doesn't seem to be the case here? Are there any typeorm settings that we can configure differently to prevent encountering this error?

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

No branches or pull requests

2 participants