From 80e82cd43f1c2ec85c405bff4b8de6f36f6d6e59 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 11 Oct 2023 15:43:02 +0200 Subject: [PATCH] Do not close transactional Connection in doReleaseConnection Closes gh-28133 --- .../r2dbc/connection/ConnectionFactoryUtils.java | 1 + .../TransactionAwareConnectionFactoryProxyUnitTests.java | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java index c128a16790a..346c5d915ce 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java @@ -178,6 +178,7 @@ public static Mono doReleaseConnection(Connection connection, ConnectionFa if (conHolder != null && connectionEquals(conHolder, connection)) { // It's the transactional Connection: Don't close it. conHolder.released(); + return Mono.empty(); } return Mono.from(connection.close()); }).onErrorResume(NoTransactionException.class, ex -> Mono.from(connection.close())); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java index 8dd4794d39b..4d6bdc7b0ac 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java @@ -146,14 +146,15 @@ void shouldEmitBoundConnection() { ConnectionFactoryUtils.getConnection(connectionFactoryMock) .doOnNext(transactionalConnection::set).flatMap(connection -> proxyCf.create() .doOnNext(wrappedConnection -> assertThat(((Wrapped) wrappedConnection).unwrap()).isSameAs(connection))) - .as(rxtx::transactional) .flatMapMany(Connection::close) + .as(rxtx::transactional) .as(StepVerifier::create) .verifyComplete(); + verify(connectionFactoryMock, times(1)).create(); + verify(connectionMock1, times(1)).close(); verifyNoInteractions(connectionMock2); verifyNoInteractions(connectionMock3); - verify(connectionFactoryMock, times(1)).create(); } }