Skip to content

Commit

Permalink
fix: [Databricks] Adding stale connection exception handling in case …
Browse files Browse the repository at this point in the history
…of cluster restart (#29890)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Improved error handling in the database connection process by
identifying and throwing an exception for stale connections.
- Enhanced error messages to include specific SQL states for better
troubleshooting.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
trishaanand authored Dec 28, 2023
1 parent b12e753 commit f8ef73b
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,21 @@ public Mono<ActionExecutionResult> execute(
}

} catch (SQLException e) {

String sqlState = e.getSQLState();
// Databricks returns true on isValid check even if the connection is stale.
// This scenario in particular happens when the connection was established before
// the cluster restarts. The sql state here corresponds to bad connection link
// and hence the correct action is to throw a StaleConnectionException.
if (sqlState != null && sqlState.equals("08S01")) {
return Mono.error(new StaleConnectionException(CONNECTION_CLOSED_ERROR_MSG));
}

return Mono.error(new AppsmithPluginException(
QUERY_EXECUTION_FAILED,
QUERY_EXECUTION_FAILED_ERROR_MSG,
e.getMessage(),
"SQLSTATE: " + e.getSQLState()));
"SQLSTATE: " + sqlState));
}

ActionExecutionResult result = new ActionExecutionResult();
Expand Down

0 comments on commit f8ef73b

Please sign in to comment.