Search code examples
mysqlspring-data-r2dbc

Does the R2DBC connection pool reuse DB connections?


I am building a spring application using R2DBC and MySQL. Running an application by deploying it on a server, I noticed a few surprising things.

  1. MySQL connection id grows very fast. my database server already exceeded 1 million connection IDs in 10 days.
  2. As a result of checking with the SHOW PROCESSLIST command, it seems that after R2DBC queries the database, it closes and reconnects instead of returning it to the connection pool immediately. The screenshot is when the application is running the query. The part that says "unauthenticated user" seems to reestablish the database connection. enter image description here
  3. This seems to cause excessive CPU usage on the database.

My opinion is that if it is a connection pool, it should be used as it is by inheriting the connection, rather than unconditionally closing and reopening the connection when returning it.

Is this behavior intentional in R2DBC? Or is it a connection pool management bug?


Solution

  • This issue occurred because the version of the R2DBC Pool library referenced in Spring Boot had a bug that immediately evicts the connection pool after use. After upgrading the version of the R2DBC Pool library to 0.9.1, the issue was resolved.

    Related PR : https://github.com/r2dbc/r2dbc-pool/issues/129