Do not close transactional Connection in doReleaseConnection

Closes gh-28133
This commit is contained in:
Juergen Hoeller
2023-10-11 15:51:58 +02:00
parent 704650de6d
commit 0370aa6007
2 changed files with 8 additions and 4 deletions

View File

@@ -176,6 +176,7 @@ public abstract class ConnectionFactoryUtils {
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()));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -54,14 +54,16 @@ class TransactionAwareConnectionFactoryProxyUnitTests {
R2dbcTransactionManager tm;
@BeforeEach
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
void before() {
when(connectionFactoryMock.create()).thenReturn((Mono) Mono.just(connectionMock1),
(Mono) Mono.just(connectionMock2), (Mono) Mono.just(connectionMock3));
tm = new R2dbcTransactionManager(connectionFactoryMock);
}
@Test
void createShouldWrapConnection() {
new TransactionAwareConnectionFactoryProxy(connectionFactoryMock).create()
@@ -143,14 +145,15 @@ class TransactionAwareConnectionFactoryProxyUnitTests {
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();
}
}