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

R2dbcNonTransientResourceException: Connection validation failed #209

Open
menakaprabu opened this issue Apr 5, 2024 · 6 comments
Open

Comments

@menakaprabu
Copy link

Hi,
I am getting this issue "org.springframework.dao.DataAccessResourceFailureException: Failed to obtain R2DBC Connection nested exception. Caused by io.r2dbc.spi.R2dbcNonTransientResourceException: Connection validation failed" in MSSQL. I am using below libraries(Version).

io.r2dbc r2dbc-pool 1.0.0.RELEASE io.r2dbc r2dbc-mssql 1.0.0.RELEASE I am seeing this issue in both pre-prod and production environment intermittently. Could you please help me with this? Thanks.
@mp911de
Copy link
Member

mp911de commented Apr 9, 2024

Is there more to the stack trace? Typically, the cause shows the reason for the validation failure.

@menakaprabu
Copy link
Author

menakaprabu commented Apr 9, 2024 via email

@MBecM
Copy link

MBecM commented Apr 10, 2024

Maybe I will add more information, because I'm fighting with the same problem for the last couple of days.

Versions

  • Driver: r2dbc-postgres
  • Database: postgres
  • Java: 21
  • io.r2dbc:r2dbc-spi:1.0.0.RELEASE
  • io.r2dbc:r2dbc-pool:1.0.1.RELEASE

Stacktrace

io.r2dbc.spi.R2dbcNonTransientResourceException: Connection validation failed
  at io.r2dbc.pool.Validation.lambda$validate$2(Validation.java:45)
  at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.onNext(FluxHandleFuseable.java:179)
  at reactor.core.publisher.MonoSupplier$MonoSupplierSubscription.request(MonoSupplier.java:145)
  at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.request(FluxHandleFuseable.java:260)
  at reactor.core.publisher.MonoIgnoreElements$IgnoreElementsSubscriber.onSubscribe(MonoIgnoreElements.java:72)
  at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.onSubscribe(FluxHandleFuseable.java:164)
  at reactor.core.publisher.MonoSupplier.subscribe(MonoSupplier.java:48)

Pool configuration

default

Additional context

This issue happens in my case 2-3 times a day in different day time. It is totally random when will it happen. What is more interesting, that after some time (10-20sec) everything goes back to normal work. So it "heals" itself, but during this 10-20sec non of my queries are executed. During my investigation I found that validation is performed 2 times.

  1. During connectionFactory.create()
    conn = getValidConnection(allocateValidation, connection);
  2. After query during connectionFactory.close()
    return Validation.validate(this, ValidationDepth.LOCAL).then(Mono.defer(() -> {

In my case it happens only on 1 case, that's why query is not executed, because connection is not acquired from connection pool. Stacktrace is also not very helpful, because it points only to 45 line in Validation.class

sink.error(new R2dbcNonTransientResourceException("Connection validation failed"));

Steps to reproduce

Restart database server between queries.

  1. Start application
  2. Execute query
  3. Restart database server: sudo pg_ctl restart / Ubuntu: sudo pg_ctlcluster 14 main restart
  4. Execute query (should FAIL with provided stacktrace)

Related issues

#138
#107

Possible Solution
The only way to mitigate this problem I found was to increase default acquireRetry property from 1 to 10, which is maxSize value.

In that case the following Mono<Connection> create will retry until it find valid connection.

this.create = configuration.getAcquireRetry() > 0 ? create.retry(configuration.getAcquireRetry()) : create;

But I'm afraid that this only hides/delays the problem and makes it even more unpredictable.
@mp911de correct me if I'm wrong. With my solution, connection pool will try 10 times to acquire connection until it founds valid connection, so basically "searches" through entire pool to find what it needs. I assume that if none of connection is valid then this exception would be fired.

@menakaprabu
Copy link
Author

menakaprabu commented Apr 10, 2024 via email

@menakaprabu
Copy link
Author

Hi @mp911de ,

Do you have any update for me. This issue is acting like a blocker, please let me know if you need more details from me.
-Thanks.

@menakaprabu
Copy link
Author

menakaprabu commented Apr 30, 2024 via email

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

No branches or pull requests

3 participants