You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "MartijnVisser (via GitHub)" <gi...@apache.org> on 2026/10/05 17:37:37 UTC
[PR] [FLINK-36146][connector-base] Fix SingleThreadFetcherManager race condition [flink]
MartijnVisser opened a new pull request, #29386:
URL: https://github.com/apache/flink/pull/29386
## What is the purpose of the change
`SingleThreadFetcherManager#getRunningFetcher()` checks `fetchers.isEmpty()` and then reads the first value. A fetcher thread can remove itself from the map in between, so `addSplits()` fails with `NoSuchElementException`.
This is Kim Gräsman's fix from #25340. Becket approved the fix and asked for a test; the stale bot closed the PR after Kim added one. I rebased it and reworked the test.
## Brief change log
- Take the running fetcher from a single iterator.
- Add a repeated test for `addSplits()` while the manager closes.
## Verifying this change
`SplitFetcherManagerTest#testAddSplitsWhileClosing` failed in all 100 class runs without the fix (2998 of 10000 repetitions) and in none of 1000 with it, under CPU load. It closes the manager because that reliably makes fetcher threads remove themselves; how the reader in the Jira hit it while running is unclear.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): no
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
- The serializers: no
- The runtime per-record code paths (performance sensitive): no
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
- The S3 file system connector: no
## Documentation
- Does this pull request introduce a new feature? no
- If yes, how is the feature documented? not applicable
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes (please specify the tool below)
Generated-by: Claude Code (Claude Opus 5.5)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-36146][connector-base] Fix SingleThreadFetcherManager race condition [flink]
Posted by "kimgr (via GitHub)" <gi...@apache.org>.
kimgr commented on PR #29386:
URL: https://github.com/apache/flink/pull/29386#issuecomment-6031432379
Thank you for getting this fixed (and tested)!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-36146][connector-base] Fix SingleThreadFetcherManager race condition [flink]
Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #29386:
URL: https://github.com/apache/flink/pull/29386#discussion_r4188325041
##########
flink-connectors/flink-connector-base/src/test/java/org/apache/flink/connector/base/source/reader/fetcher/SplitFetcherManagerTest.java:
##########
@@ -309,6 +311,40 @@ void testIdleShutdownSplitFetcherWaitsUntilRecordProcessed() throws Exception {
}
}
+ @RepeatedTest(100)
+ void testAddSplitsWhileClosing() throws Exception {
Review Comment:
```java
@Test
void getRunningFetcherSurvivesFetcherRemovalInToctouWindow() throws Exception {
final SingleThreadFetcherManager<Object, TestingSourceSplit> fetcherManager =
new SingleThreadFetcherManager<>(TestingSplitReader::new, new Configuration());
final SplitFetcher<Object, TestingSourceSplit> fetcher = fetcherManager.createSplitFetcher();
final Map<Integer, SplitFetcher<Object, TestingSourceSplit>> racyFetchers =
new ConcurrentHashMap<Integer, SplitFetcher<Object, TestingSourceSplit>>() {
private boolean removed;
@Override
public Collection<SplitFetcher<Object, TestingSourceSplit>> values() {
// The shutdown callback (fetchers.remove(...)) fires here: after
// getRunningFetcher()'s isEmpty() check saw the entry, before it is read.
if (!removed) {
removed = true;
clear();
}
return super.values();
}
};
racyFetchers.put(0, fetcher);
final Field fetchersField = SplitFetcherManager.class.getDeclaredField("fetchers");
fetchersField.setAccessible(true);
fetchersField.set(fetcherManager, racyFetchers);
assertThat(fetcherManager.getRunningFetcher()).isNull();
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-36146][connector-base] Fix SingleThreadFetcherManager race condition [flink]
Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #29386:
URL: https://github.com/apache/flink/pull/29386#discussion_r4188327172
##########
flink-connectors/flink-connector-base/src/test/java/org/apache/flink/connector/base/source/reader/fetcher/SplitFetcherManagerTest.java:
##########
@@ -309,6 +311,40 @@ void testIdleShutdownSplitFetcherWaitsUntilRecordProcessed() throws Exception {
}
}
+ @RepeatedTest(100)
+ void testAddSplitsWhileClosing() throws Exception {
Review Comment:
it should fail in 100%
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-36146][connector-base] Fix SingleThreadFetcherManager race condition [flink]
Posted by "MartijnVisser (via GitHub)" <gi...@apache.org>.
MartijnVisser commented on code in PR #29386:
URL: https://github.com/apache/flink/pull/29386#discussion_r4187136146
##########
flink-connectors/flink-connector-base/src/test/java/org/apache/flink/connector/base/source/reader/fetcher/SplitFetcherManagerTest.java:
##########
@@ -309,6 +311,40 @@ void testIdleShutdownSplitFetcherWaitsUntilRecordProcessed() throws Exception {
}
}
+ @RepeatedTest(100)
+ void testAddSplitsWhileClosing() throws Exception {
Review Comment:
No, without the fix a single attempt fails about one time in three (3341 of 10000 locally). The window sits between `isEmpty()` and `next()` inside `ConcurrentHashMap`, so there is no hook to force it. All 100 repetitions take about 80 ms.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-36146][connector-base] Fix SingleThreadFetcherManager race condition [flink]
Posted by "MartijnVisser (via GitHub)" <gi...@apache.org>.
MartijnVisser commented on code in PR #29386:
URL: https://github.com/apache/flink/pull/29386#discussion_r4192260687
##########
flink-connectors/flink-connector-base/src/test/java/org/apache/flink/connector/base/source/reader/fetcher/SplitFetcherManagerTest.java:
##########
@@ -309,6 +311,40 @@ void testIdleShutdownSplitFetcherWaitsUntilRecordProcessed() throws Exception {
}
}
+ @RepeatedTest(100)
+ void testAddSplitsWhileClosing() throws Exception {
Review Comment:
You're right, overriding `values()` makes it deterministic. I've replaced the repeated test with yours and added you as co-author. It fails on master and passes with the fix on JDK 17 and 21.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-36146][connector-base] Fix SingleThreadFetcherManager race condition [flink]
Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #29386:
URL: https://github.com/apache/flink/pull/29386#discussion_r4187055997
##########
flink-connectors/flink-connector-base/src/test/java/org/apache/flink/connector/base/source/reader/fetcher/SplitFetcherManagerTest.java:
##########
@@ -309,6 +311,40 @@ void testIdleShutdownSplitFetcherWaitsUntilRecordProcessed() throws Exception {
}
}
+ @RepeatedTest(100)
+ void testAddSplitsWhileClosing() throws Exception {
Review Comment:
why do we need it?
can it be reproduced in 100% with first attempt?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-36146][connector-base] Fix SingleThreadFetcherManager race condition [flink]
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #29386:
URL: https://github.com/apache/flink/pull/29386#issuecomment-5999998771
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "51741cc1916ab6e2f394472552f1da8b2278b265",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "51741cc1916ab6e2f394472552f1da8b2278b265",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 51741cc1916ab6e2f394472552f1da8b2278b265 UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run azure` re-run the last Azure build
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-36146][connector-base] Fix SingleThreadFetcherManager race condition [flink]
Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #29386:
URL: https://github.com/apache/flink/pull/29386#discussion_r4188318825
##########
flink-connectors/flink-connector-base/src/test/java/org/apache/flink/connector/base/source/reader/fetcher/SplitFetcherManagerTest.java:
##########
@@ -309,6 +311,40 @@ void testIdleShutdownSplitFetcherWaitsUntilRecordProcessed() throws Exception {
}
}
+ @RepeatedTest(100)
+ void testAddSplitsWhileClosing() throws Exception {
Review Comment:
how about this instead?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-36146][connector-base] Fix SingleThreadFetcherManager race condition [flink]
Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on PR #29386:
URL: https://github.com/apache/flink/pull/29386#issuecomment-6011871611
fyi after analyzing code for similar patterns I found another issue like that https://github.com/apache/flink/pull/29399
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-36146][connector-base] Fix SingleThreadFetcherManager race condition [flink]
Posted by "MartijnVisser (via GitHub)" <gi...@apache.org>.
MartijnVisser merged PR #29386:
URL: https://github.com/apache/flink/pull/29386
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org