[SQL] Add configurable retry attempts and backoff delay for JDBC connection establishment - #58925
Open
CodersAcademy006 wants to merge 1 commit into
Open
CodersAcademy006 wants to merge 1 commit into
CodersAcademy006 wants to merge 1 commit into
Conversation
CodersAcademy006
force-pushed
the
fix-jdbc-connection-retry
branch
from
September 19, 2026 05:51
77d5014 to
4092174
Compare
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.
We ran into this at work — our ETL pipelines read from AWS RDS Postgres, and during RDS failovers (which last ~10-20s), every JDBC reader task would just blow up immediately because there's no retry on connection establishment.
For writers it's fine since you can wrap the write call in your own retry loop. But for readers the connection factory is baked into the RDD partition and you can't intercept it once the plan is materialized.
Looked through the JDBC internals and there's genuinely no retry/backoff anywhere in the connection path —
JdbcDialect.createConnectionFactorycallsConnectionProvider.createand if that throws, the task dies.What I did:
Added two new JDBC options:
connectionRetryAttempts— how many times to retry (default 0, so existing behavior is unchanged)connectionRetryDelayMs— sleep between retries in ms (default 1000)The retry logic lives in a new
JdbcUtils.createConnectionFactory(dialect, options)wrapper rather than insideJdbcDialect.createConnectionFactoryitself. This way custom dialect overrides still work and automatically get retry behavior on top.Only retries on transient connection errors — specifically
SQLTransientConnectionExceptionorSQLExceptionwith SQLState class08(connection exception). Auth failures, bad queries, etc. fail immediately on the first attempt.Also made sure the retry loop checks
TaskContext.isInterrupted()before and after sleeping so task cancellation doesn't get blocked by the backoff delay.Updated all call sites (
JDBCRDD,JdbcRelationProvider,JdbcUtils.withConnection,JDBCWriteBuilder) to go through the wrapper.Tests:
Added
JDBCConnectionRetrySuitewith tests for:Closes #58474.