Fix closeOnCompletion() infinite recursion on ResultSet/Statement close (ES-1978361)#1493
Open
sreekanth-db wants to merge 1 commit into
Open
Conversation
ResultSet.close() and Statement.close() recursed into each other indefinitely when closeOnCompletion() was enabled, causing a StackOverflowError / apparent hang after a successful query. Make ResultSet.close() idempotent: return early if already closed, and set isClosed before notifying the parent Statement so the re-entrant close triggered via handleResultSetClose() short-circuits at the guard. Adds regression tests for both entry points (ResultSet.close() and Statement.close()) with closeOnCompletion() enabled. Co-authored-by: Isaac Signed-off-by: Sreekanth Vadigi <sreekanth.vadigi@databricks.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes ES-1978361: with
Statement.closeOnCompletion()enabled, closing theResultSet(orStatement) recursed infinitely betweenResultSet.close()andStatement.close(), producing aStackOverflowErrorthat surfaced to users as an indefinite hang after a successful query (thread blocked in the SSL socket read of a half-torn-down operation,statement.isClosed()stuckfalse).Root cause
closeOnCompletion()creates a mutual-recursion cycle with no idempotency guard:Statement.close()closes itsResultSet.ResultSet.close()calls back intoStatement.handleResultSetClose().closeOnCompletionis set, that callsStatement.close()again → step 1.ResultSet.close()had no "already closed" check, so the cycle never terminated.Fix
Make
ResultSet.close()idempotent: return early if already closed, and setisClosedbefore notifying the parentStatement, so the re-entrant close triggered viahandleResultSetClose()short-circuits at the guard. Minimal, targeted change; no behavior change on the normal close path.Testing
DatabricksStatementTest) covering both entry points —ResultSet.close()andStatement.close()— withcloseOnCompletion()enabled. Verified they fail withStackOverflowErrorwithout the fix and pass with it.DatabricksStatementTest+DatabricksResultSetTest(185 tests) pass.rs.close()completes promptly,rs.isClosed()andstmt.isClosed()bothtrue, no crash.This pull request and its description were written by Isaac.