Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of bad connection errors and specifying server protocol. #152

Merged
merged 1 commit into from Aug 30, 2023

Conversation

rcypher-databricks
Copy link
Contributor

Added a new error type that identifies as driver.ErrBadConn. This can be added in to an error chain to signal that a connection should no longer be used and to retry with a new connection.

Updated ThriftServiceClient error handling. When a Thrift request fails we are now checking the error message for the term 'Invalid SessionHandle'. If it is present we are adding a bad connection error to the error chain. Searching in the error message is clumsy and fragile but there doesn't currently appear to be another way to get the information.

Updated the WithServerHostname function to handle host names prefixed by 'http:' or 'https:' to allow users to specify which protocol to use. This is in response to github issue #140.

… be added in to an error chain to signal that a connection should no longer be used and to retry with a new connection.

Updated ThriftServiceClient error handling. When a Thrift request fails we are now checking the error message for the term 'Invalid SessionHandle'.  If it is present we are adding a bad connection error to the error chain.  Searching in the error message is clumsy and fragile but there doesn't currently appear to be another way to get the information.

Updated the WithServerHostname function to handle host names prefixed by 'http:' or 'https:' to allow users to specify which protocol to use.  This is in response to github issue databricks#140.

Signed-off-by: Raymond Cypher <raymond.cypher@databricks.com>
// If the passed error indicates an invalid session we inject a bad connection error
// into the error stack. This allows the for retrying with a new connection.
s := err.Error()
if strings.Contains(s, "Invalid SessionHandle") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to be very careful with session state. If the user expects some state - temp views, etc - and we just open a new session in the background, it may be very hard to understand and debug what is going on.

Copy link
Contributor

@aldld aldld Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the context of database/sql, if the user is using methods on the sql.DB object directly (e.g. db.QueryContext(...)) then they cannot rely on maintaining per-session state anyway because these methods might create new connections or reuse an arbitrary connection from the pool.

If a user does need to rely on per-session state, then doing so correctly requires explicitly grabbing a connection and then calling methods on the connection. In that case, it's the user's responsibility to manage the connection lifecycle, which includes handling errors and accounting for the possibility that a connection may end up in a bad state.

@rcypher-databricks rcypher-databricks marked this pull request as draft August 3, 2023 19:23
@rcypher-databricks rcypher-databricks marked this pull request as ready for review August 16, 2023 22:18
// into the error stack. This allows the for retrying with a new connection.
s := err.Error()
if strings.Contains(s, "Invalid SessionHandle") {
err = dbsqlerrint.NewBadConnectionError(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, looks like the NewBadConnectionError will be wrapped again in a NewRequestError. Would it be better to just return the error as is? Or is the client expecting a NewRequestError?

@rcypher-databricks rcypher-databricks merged commit 7a177c9 into databricks:main Aug 30, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants