Skip to content

Commit 6ff3aff

Browse files
GH-1502: [JDBC] Only ignore no-session statuses from CloseSession without a catalog
1 parent a39039f commit 6ff3aff

2 files changed

Lines changed: 34 additions & 8 deletions

File tree

‎flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandler.java‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.ArrayList;
2929
import java.util.Arrays;
3030
import java.util.Collection;
31+
import java.util.EnumSet;
3132
import java.util.HashSet;
3233
import java.util.List;
3334
import java.util.Map;
@@ -86,6 +87,15 @@ public final class ArrowFlightSqlClientHandler implements AutoCloseable {
8687
@VisibleForTesting
8788
static final CallOption CLOSE_SESSION_TIMEOUT = CallOptions.timeout(5, TimeUnit.SECONDS);
8889

90+
// No session to close: CloseSession is unsupported or unknown, none was created, or the
91+
// client is not (or no longer) authenticated.
92+
private static final Set<FlightStatusCode> NO_SESSION_STATUS_CODES =
93+
EnumSet.of(
94+
FlightStatusCode.UNIMPLEMENTED,
95+
FlightStatusCode.INVALID_ARGUMENT,
96+
FlightStatusCode.NOT_FOUND,
97+
FlightStatusCode.UNAUTHENTICATED);
98+
8999
private final String cacheKey;
90100
private final FlightSqlClient sqlClient;
91101
private final Set<CallOption> options = new HashSet<>();
@@ -318,12 +328,11 @@ private void closeSession() throws SQLException {
318328
sqlClient.closeSession(new CloseSessionRequest(), closeSessionOptions);
319329
}
320330
} catch (FlightRuntimeException fre) {
321-
if (catalog.isPresent()) {
331+
if (catalog.isEmpty() && NO_SESSION_STATUS_CODES.contains(fre.status().code())) {
332+
logSuppressedCloseException(fre, "closing Flight SQL session");
333+
} else {
322334
handleBenignCloseException(
323335
fre, "Failed to close Flight SQL session.", "closing Flight SQL session");
324-
} else {
325-
// Without a catalog the driver never asked for a session; the server may not support them.
326-
logSuppressedCloseException(fre, "closing Flight SQL session");
327336
}
328337
}
329338
}

‎flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/client/ArrowFlightSqlClientHandlerTest.java‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,12 @@ public void testCloseHandlesFlightRuntimeException(
151151
verify(sqlClient).close();
152152
}
153153

154-
@Test
155-
public void testCloseSessionWithoutCatalogIsBestEffortWithTimeout() throws Exception {
154+
@ParameterizedTest
155+
@MethodSource
156+
public void testCloseSessionWithoutCatalog(FlightStatusCode code, boolean shouldSuppress)
157+
throws Exception {
156158
FlightSqlClient sqlClient = mock(FlightSqlClient.class);
157-
doThrow(CallStatus.UNKNOWN.toRuntimeException())
159+
doThrow(new CallStatus(code, null, null, null).toRuntimeException())
158160
.when(sqlClient)
159161
.closeSession(any(CloseSessionRequest.class), any(CallOption[].class));
160162
ArrowFlightSqlClientHandler sqlClientHandler =
@@ -166,13 +168,28 @@ public void testCloseSessionWithoutCatalogIsBestEffortWithTimeout() throws Excep
166168
Optional.empty(),
167169
null);
168170

169-
assertDoesNotThrow(sqlClientHandler::close);
171+
if (shouldSuppress) {
172+
assertDoesNotThrow(sqlClientHandler::close);
173+
} else {
174+
assertThrows(SQLException.class, sqlClientHandler::close);
175+
}
170176
verify(sqlClient)
171177
.closeSession(
172178
any(CloseSessionRequest.class), eq(ArrowFlightSqlClientHandler.CLOSE_SESSION_TIMEOUT));
173179
verify(sqlClient).close();
174180
}
175181

182+
private static Object[] testCloseSessionWithoutCatalog() {
183+
return new Object[] {
184+
new Object[] {FlightStatusCode.UNIMPLEMENTED, true},
185+
new Object[] {FlightStatusCode.INVALID_ARGUMENT, true},
186+
new Object[] {FlightStatusCode.NOT_FOUND, true},
187+
new Object[] {FlightStatusCode.UNAVAILABLE, true},
188+
new Object[] {FlightStatusCode.UNAUTHENTICATED, true},
189+
new Object[] {FlightStatusCode.UNKNOWN, false},
190+
};
191+
}
192+
176193
private static Object[] testCloseHandlesFlightRuntimeException() {
177194
CallStatus benignInternalError =
178195
new CallStatus(FlightStatusCode.INTERNAL, null, "Connection closed after GOAWAY", null);

0 commit comments

Comments
 (0)