Skip to content

Loading entities with query strategy and connection limit set to 1 for mysql driver will cause dead lock #9298

@Rainson12

Description

@Rainson12

Issue Description

when loading related entities using the query relationLoadStrategy it seems like after executing the sql the connection is not freed again which leads to non resolving queries because there are no more free connections in the mysql connection pool.

Expected Behavior

Connections are freed after executing the query to load related entites

Actual Behavior

Connections are not freed leaving the pool with no free connections which means further relations cant be resolved because the queries will never receive a connection to execute them which will lead to infinite loading times.

Steps to Reproduce

Create mysql db with multiple related entities one entity that has 5 one to many relations. Use

relationLoadStrategy: 'query',
"extra": {
            "connectionLimit": 1
        }

in the typeorm config.

Execute a query and see that it never finishes due to lack of available connections. It will get stuck forever at
const databaseConnection = await this.connect(); line 145 MysqlQueryRunner.hs

A working workaround would be to set the connectionLimit to a higher value like 50 or 100.

My Environment

Dependency Version
Operating System
Node.js version 16.15.0
Typescript version 4.5.4
TypeORM version 0.3.6

We are also using NestJs /typeorm version 8.1.0

Additional Context

Relevant Database Driver(s)

DB Type Reproducible
aurora-mysql no
aurora-postgres no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql yes
nativescript no
oracle no
postgres no
react-native no
sap no
spanner no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions