Skip to content

Commit 7b4f3f2

Browse files
committed
fix: keep DEFAULT_EXECUTOR_THREAD_NUMBER and withdraw polls scheduled after stop
1 parent 393ad21 commit 7b4f3f2

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingConfiguration.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ public record PerResourcePollingConfiguration<R, P extends HasMetadata, ID>(
3535
Predicate<P> registerPredicate,
3636
Duration defaultPollingPeriod) {
3737

38+
/**
39+
* @deprecated not used anymore, polls now run on the executor the operator shares between all its
40+
* scheduled tasks unless an executor is explicitly configured
41+
*/
42+
@Deprecated(forRemoval = true)
43+
public static final int DEFAULT_EXECUTOR_THREAD_NUMBER = 1;
44+
3845
public PerResourcePollingConfiguration(
3946
String name,
4047
ScheduledExecutorService executorService,

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSource.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ private void scheduleNextExecution(P primary, Set<R> actualResources) {
137137
executorService.schedule(
138138
new FetchingExecutor(primaryID), fetchDuration.toMillis(), TimeUnit.MILLISECONDS);
139139
scheduledFutures.put(primaryID, scheduledFuture);
140+
// a fetch that was already running when the event source got stopped can get here after stop
141+
// cleared the map; since the shared executor stays alive, the task has to be withdrawn,
142+
// otherwise the stale entry would prevent the resource from being registered on a restart
143+
if (!isRunning() && scheduledFutures.remove(primaryID, scheduledFuture)) {
144+
scheduledFuture.cancel(true);
145+
}
140146
}
141147

142148
@Override

0 commit comments

Comments
 (0)