Skip to content

Commit d2cb194

Browse files
committed
#928 Fix infinite loop in FBPooledConnection.fireConnectionError
(backport of #927)
1 parent 3517938 commit d2cb194

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
@@ -54,6 +54,7 @@ This results in two minor breaking changes:
5454
* Fixed: JDBC escapes should not be parsed inside dialect 3 delimited identifiers or dialect 1 string literals (https://github.com/FirebirdSQL/jaybird/issues/922[#922])
5555
* Fixed: `IndexOutOfBoundsException` in `FBCachedBlob.getBytes(long, int)` for position or length beyond end of data (https://github.com/FirebirdSQL/jaybird/issues/924[#924])
5656
* Fixed: Using native client, password is limited to 255 bytes (https://github.com/FirebirdSQL/jaybird/issues/926[#926])
57+
* Fixed: Infinite loop in `FBPooledConnection#fireConnectionError(SQLException)` if the exception has a chained exception and neither is fatal (https://github.com/FirebirdSQL/jaybird/issues/928[#928])
5758
5859
[#jaybird-5-0-11-changelog]
5960
=== Jaybird 5.0.11

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 @@ protected 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,13 +20,15 @@
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.firebirdsql.jdbc.FBSQLException;
2829
import org.firebirdsql.jdbc.SQLStateConstants;
2930
import org.junit.jupiter.api.Test;
31+
import org.junit.jupiter.api.Timeout;
3032
import org.junit.jupiter.api.extension.ExtendWith;
3133
import org.mockito.InjectMocks;
3234
import org.mockito.Mock;
@@ -190,4 +192,24 @@ void testGetConnectionRestoresAutoCommit() throws SQLException {
190192

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

0 commit comments

Comments
 (0)