Skip to content

Commit cb1dde4

Browse files
committed
#927 Fix infinite loop in FBPooledConnection.fireConnectionError
1 parent d7bd50b commit cb1dde4

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void fireConnectionError(SQLException ex) {
151151
fireFatalConnectionError(ex);
152152
return;
153153
}
154-
currentException = ex.getNextException();
154+
currentException = currentException.getNextException();
155155
}
156156
}
157157

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
// SPDX-FileCopyrightText: Copyright 2011-2024 Mark Rotteveel
1+
// SPDX-FileCopyrightText: Copyright 2011-2026 Mark Rotteveel
22
// SPDX-License-Identifier: LGPL-2.1-or-later
33
package org.firebirdsql.ds;
44

55
import java.sql.Connection;
66
import java.sql.SQLException;
7+
import java.util.concurrent.TimeUnit;
78

89
import javax.sql.ConnectionEvent;
910
import javax.sql.ConnectionEventListener;
1011

1112
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.api.Timeout;
1214
import org.junit.jupiter.api.extension.ExtendWith;
1315
import org.mockito.InjectMocks;
1416
import org.mockito.Mock;
@@ -173,4 +175,24 @@ void testGetConnectionRestoresAutoCommit() throws SQLException {
173175

174176
verify(physical).setAutoCommit(true);
175177
}
178+
179+
/**
180+
* See also <a href="https://github.com/FirebirdSQL/jaybird/issues/927">#927</a>.
181+
*/
182+
@Test
183+
@Timeout(value = 200, unit = TimeUnit.MILLISECONDS, threadMode = Timeout.ThreadMode.SEPARATE_THREAD)
184+
void noInfiniteLoopWithNonFatalChainedExceptions(@Mock ConnectionEventListener cel) throws Exception {
185+
pooled.addConnectionEventListener(cel);
186+
Connection connection = pooled.getConnection();
187+
188+
var nonFatalChainedException = new SQLException("Not fatal");
189+
nonFatalChainedException.setNextException(new SQLException("Not fatal either"));
190+
doThrow(nonFatalChainedException).when(physical).setAutoCommit(false);
191+
192+
var exception = assertThrows(SQLException.class, () -> connection.setAutoCommit(false));
193+
assertSame(nonFatalChainedException, exception);
194+
195+
verify(cel, never()).connectionErrorOccurred(any(ConnectionEvent.class));
196+
}
197+
176198
}

0 commit comments

Comments
 (0)