Skip to content

Commit 453b78b

Browse files
committed
#927 Fix infinite loop in FBPooledConnection.fireConnectionError
1 parent d17765d commit 453b78b

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/docs/asciidoc/release_notes.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ This results in two minor breaking changes:
5151
* Fixed: JDBC escapes should not be parsed inside dialect 3 delimited identifiers or dialect 1 string literals (https://github.com/FirebirdSQL/jaybird/issues/921[#921])
5252
* Fixed: `IndexOutOfBoundsException` in `FBCachedBlob.getBytes(long, int)` for position or length beyond end of data (https://github.com/FirebirdSQL/jaybird/issues/923[#923])
5353
* Fixed: Using native client, password is limited to 255 bytes (https://github.com/FirebirdSQL/jaybird/issues/925[#925])
54+
* Fixed: Infinite loop in `FBPooledConnection#fireConnectionError(SQLException)` if the exception has a chained exception and neither is fatal (https://github.com/FirebirdSQL/jaybird/issues/927[#927])
5455

5556
=== Jaybird 6.0.4
5657

src/main/org/firebirdsql/ds/FBPooledConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void fireConnectionError(SQLException ex) {
161161
fireFatalConnectionError(ex);
162162
return;
163163
}
164-
currentException = ex.getNextException();
164+
currentException = currentException.getNextException();
165165
}
166166
}
167167

src/test/org/firebirdsql/ds/FBPooledConnectionMockTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020

2121
import java.sql.Connection;
2222
import java.sql.SQLException;
23+
import java.util.concurrent.TimeUnit;
2324

2425
import javax.sql.ConnectionEvent;
2526
import javax.sql.ConnectionEventListener;
2627

2728
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.api.Timeout;
2830
import org.junit.jupiter.api.extension.ExtendWith;
2931
import org.mockito.InjectMocks;
3032
import org.mockito.Mock;
@@ -189,4 +191,24 @@ void testGetConnectionRestoresAutoCommit() throws SQLException {
189191

190192
verify(physical).setAutoCommit(true);
191193
}
194+
195+
/**
196+
* See also <a href="https://github.com/FirebirdSQL/jaybird/issues/927">#927</a>.
197+
*/
198+
@Test
199+
@Timeout(value = 200, unit = TimeUnit.MILLISECONDS, threadMode = Timeout.ThreadMode.SEPARATE_THREAD)
200+
void noInfiniteLoopWithNonFatalChainedExceptions(@Mock ConnectionEventListener cel) throws Exception {
201+
pooled.addConnectionEventListener(cel);
202+
Connection connection = pooled.getConnection();
203+
204+
var nonFatalChainedException = new SQLException("Not fatal");
205+
nonFatalChainedException.setNextException(new SQLException("Not fatal either"));
206+
doThrow(nonFatalChainedException).when(physical).setAutoCommit(false);
207+
208+
var exception = assertThrows(SQLException.class, () -> connection.setAutoCommit(false));
209+
assertSame(nonFatalChainedException, exception);
210+
211+
verify(cel, never()).connectionErrorOccurred(any(ConnectionEvent.class));
212+
}
213+
192214
}

0 commit comments

Comments
 (0)