[FLINK-39975][jdbc] Recover JdbcSourceSplitReader from a connection closed during cancellation#200
Merged
RocMarshal merged 1 commit intoJun 23, 2026
Conversation
0deff58 to
fc2003d
Compare
RocMarshal
approved these changes
Jun 23, 2026
RocMarshal
left a comment
Contributor
There was a problem hiding this comment.
LGTM +1.
Thanks @laughingman7743
RocMarshal
reviewed
Jun 23, 2026
…losed during cancellation When a bounded query (e.g. LIMIT) finishes the job early, the source is cancelled while the split fetcher is still opening the next split. The JDBC connection validated by the provider is torn down before the statement is prepared/executed, so Derby raises "08003: No current connection"; the fatal SQLException fails the whole job and makes DerbyDynamicTableSourceITCase.testLimit flaky. Wrap the split-open in a bounded retry: when the connection is found closed, drop it together with the stale statement/result set and re-establish it via the provider, retrying up to MAX_CONNECTION_RETRIES. A genuine query error on a healthy connection is rethrown immediately, and an unreachable database still fails the job after the retry budget, so real errors are not masked. wakeUp()/fetch() are left unchanged. Add a deterministic regression test that injects an already-closed connection (reproducing the exact 08003 and failing without the fix), plus tests for the immediate-rethrow and retry-exhaustion branches.
fc2003d to
76593c8
Compare
|
Awesome work, congrats on your first merged pull request! |
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.
What is the purpose of the change
Fix the flaky
DerbyDynamicTableSourceITCase.testLimit(and occasionallytestProject). When a bounded query (e.g.LIMIT) finishes the job early, the source is cancelled while the split fetcher is still opening the next split; theJDBC connection validated by the provider is torn down before the statement is prepared/executed, so Derby raises
08003: No current connectionand the fatalSQLExceptionfails the whole job (the test runs underNoRestartBackoffTimeStrategy). See FLINK-39975 for the full analysis.Brief change log
JdbcSourceSplitReadernow opens a split viaopenResultSetForSplitWithReconnect, a bounded retry (MAX_CONNECTION_RETRIES = 3).connection.isClosed()); before retrying it drops the dead connection and the stale statement/result set and re-establishes via the provider. A query error on a healthyconnection is rethrown immediately, and an unreachable database still fails after the retry budget — real errors are not masked.
wakeUp()/fetch()are unchanged.Verifying this change
JdbcSourceSplitReaderTest#testFetchReconnectsWhenConnectionClosedWhileOpeningSplit, a deterministic regression test that injects an already-closed connection, reproducing the exact08003error (it fails without thischange) and asserting the reader re-establishes the connection and reads the whole split.
testFetchRethrowsImmediatelyWhenConnectionStaysOpen(a query error on a healthy connection is rethrown without reconnect) andtestFetchFailsAfterExhaustingReconnectRetries(gives up after the retry budget instead oflooping forever).
DerbyDynamicTableSourceITCasepasses repeated runs.Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation