Skip to content

Commit b572b7c

Browse files
vinodkcdongjoon-hyun
authored andcommitted
[SPARK-54550][CONNECT] Handle ConnectException gracefully in SparkConnectStatement.close()
### What changes were proposed in this pull request? This PR fixes two issues in `org.apache.spark.sql.connect.client.jdbc.SparkConnectStatement.close()`: - Added `try-catch` to silently handle `ConnectException` during `interruptOperation()` when the server is unavailable - Fixed bug: changed closed = false to closed = true at the end of the method ### Why are the changes needed? - ConnectException handling: The `SparkConnectStatement.close()` method should not throw exceptions during cleanup. Connection exceptions during cleanup are not actionable and only mask more important exceptions. - closed flag bug: Setting closed = false is incorrect and could allow reuse of closed statements. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Existing unit tests pass ### Was this patch authored or co-authored using generative AI tooling? No Closes #53260 from vinodkc/br_handle_close_exception. Authored-by: vinodkc <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]> (cherry picked from commit bb36695) Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent e00cd4e commit b572b7c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

sql/connect/client/jdbc/src/main/scala/org/apache/spark/sql/connect/client/jdbc/SparkConnectStatement.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,21 @@ class SparkConnectStatement(conn: SparkConnectConnection) extends Statement {
3535
override def close(): Unit = synchronized {
3636
if (!closed) {
3737
if (operationId != null) {
38-
conn.spark.interruptOperation(operationId)
38+
try {
39+
conn.spark.interruptOperation(operationId)
40+
} catch {
41+
case _: java.net.ConnectException =>
42+
// Ignore ConnectExceptions during cleanup as the operation may have already completed
43+
// or the server may be unavailable. The important part is marking this statement
44+
// as closed to prevent further use.
45+
}
3946
operationId = null
4047
}
4148
if (resultSet != null) {
4249
resultSet.close()
4350
resultSet = null
4451
}
45-
closed = false
52+
closed = true
4653
}
4754
}
4855

0 commit comments

Comments
 (0)