Skip to content

Commit

Permalink
Do not close transactional Connection in doReleaseConnection
Browse files Browse the repository at this point in the history
Closes gh-28133
  • Loading branch information
jhoeller committed Oct 11, 2023
1 parent 704650d commit 0370aa6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public static Mono<Void> 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()));
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -143,14 +145,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();
}

}

0 comments on commit 0370aa6

Please sign in to comment.