r2dbc / r2dbc-pool

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

readonly transactions used in section where no readonly transactions are allowed (happens only if there are readonly sections elsewhere) #212

Open anschnapp opened 3 months ago

anschnapp commented 3 months ago

Bug Report

Versions

Current Behavior

I have a little spring boot service which used r2dbc with the pool.

I have multiple endpoints which at the end are calling code which supports transactions. Some are readonly (and therefore have no write operations) and some are transactions with readonly=false which does some write operations.

From our logs we realized that we sometimes we got issues with read only transactions trying to do some write operations. But these issues was happening at code sections which are configured for using "writeable transactions".

We assume that the pool will reuse some connection which had a readonly flag for writeable transactions.

For now as a workaround we removed the read only tx blocks completely and the error is gone.

Steps to reproduce

I guess it might be reproducable if you had a service with readonly and not readonly operations and simulate a high load. However this time i don't have found the time for a "minimal reproducable example project".

Expected behavior/code

Read only transactions should never be used in code which required a transaction of read only = false. Regardless if readonly transactions are used in other sections of the code.

Possible Solution

Check if connection with readonly = true are somehow reused, and if it could happen that they are reused for "writeable transactions". (and then fix it ;))