fix(csharp): surface closed/expired sessions as a clear, typed error - #510
Open
jadewang-db wants to merge 1 commit into
Open
fix(csharp): surface closed/expired sessions as a clear, typed error#510jadewang-db wants to merge 1 commit into
jadewang-db wants to merge 1 commit into
Conversation
When a server-side session is closed or times out due to inactivity, the next Thrift call returns HTTP 400 "Invalid SessionHandle". The driver previously surfaced this as a misleading "An unexpected error occurred while fetching results / Couldn't connect to server" wrapper, and kept reusing the now-stale handle so every subsequent call failed the same opaque way until the caller disposed and re-created the connection. Tier 1 (clear, typed error): detect the closed/expired-session signature and surface it as a typed DatabricksSessionExpiredException (AdbcStatusCode.InvalidState) with a clear message, preserving the original error as InnerException for diagnostics. Tier 2 (fail fast): mark the connection's session invalid on first detection so subsequent statements fail fast with the same typed error instead of reusing the dead handle. Detection walks the inner/aggregate exception chain for the stable server phrase "Invalid SessionHandle" (covers both the inactivity-timeout "Session [..] is closed" and explicit-close variants) and is careful not to misclassify connectivity errors or invalid *operation* handles. Tests: - Unit tests for the classifier (no workspace required, runs in CI). - E2E test that reproduces the condition on demand by closing the session out-of-band, asserting both the typed Tier 1 error and Tier 2 fast-fail. Co-authored-by: Isaac
msrathore-db
reviewed
Jun 4, 2026
| /// and the explicitly-closed variant ("Invalid SessionHandle: SessionHandle [..]") | ||
| /// contain this phrase. | ||
| /// </summary> | ||
| internal const string ServerErrorSignature = "Invalid SessionHandle"; |
Collaborator
There was a problem hiding this comment.
is there no better way to identify this?
msrathore-db
reviewed
Jun 4, 2026
|
|
||
| public override QueryResult ExecuteQuery() | ||
| /// <summary> | ||
| /// Tier 2 fast-fail: if the connection's server-side session is already known to be |
Collaborator
There was a problem hiding this comment.
Tier 2 fast-fails emit no telemetry
msrathore-db
reviewed
Jun 4, 2026
msrathore-db
left a comment
Collaborator
There was a problem hiding this comment.
We need to do the same for metadata and fetch paths also right?
Collaborator
|
I think this logic should happen in the HiveServer2Connection class: https://github.com/adbc-drivers/hiveserver2/blob/main/csharp/src/AdbcDrivers.HiveServer2/Hive2/HiveServer2Statement.cs#L360C85-L360C105. We can change the SessionHandle to something like this: Then this will guard for every Thrift operation and we do not need to manually edit the callsite one by one. |
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.
When a server-side session is closed or times out due to inactivity, the next Thrift call returns HTTP 400 "Invalid SessionHandle". The driver previously surfaced this as a misleading "An unexpected error occurred while fetching results / Couldn't connect to server" wrapper, and kept reusing the now-stale handle so every subsequent call failed the same opaque way until the caller disposed and re-created the connection.
Tier 1 (clear, typed error): detect the closed/expired-session signature and surface it as a typed DatabricksSessionExpiredException (AdbcStatusCode.InvalidState) with a clear message, preserving the original error as InnerException for diagnostics.
Tier 2 (fail fast): mark the connection's session invalid on first detection so subsequent statements fail fast with the same typed error instead of reusing the dead handle.
Detection walks the inner/aggregate exception chain for the stable server phrase "Invalid SessionHandle" (covers both the inactivity-timeout "Session [..] is closed" and explicit-close variants) and is careful not to misclassify connectivity errors or invalid operation handles.
Tests: