r2dbc / r2dbc-pool

Connection Pooling for Reactive Relational Database Connectivity
https://r2dbc.io
Apache License 2.0
331 stars 55 forks source link

R2dbc connection pool returns multiple pooled objects pointing to same database connection #211

Open Azukovskij opened 3 months ago

Azukovskij commented 3 months ago

R2dbc returns multiple pooled objects pointing to same database connection in case downstream gets disposed, e.g.

Dispose event in downstream causes ref.release().subscribe(); to be invoked that releases pooled references (without calling preDestroy or any kind of logging event). As a result another pending invocation ConnectionPool#create receives same database connection, that has not yet been closed and has not finished processing in initial subscription.

This causes connection sharing issues on higher load that lead to lost cursor and data consistency issues (when transactions are leaked).

Please see https://github.com/r2dbc/r2dbc-pool/pull/210 for unit test reproducing the issue and proposed solution - in case more full-proof solution is required connection dispose hook can be added on PooledConnection via Cleaner