GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: create the PollingEventSource timer on start and make it a daemon by csviri · Pull Request #3523 · operator-framework/java-operator-sdk

Conversation

@csviri

@csviri csviri commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

PollingEventSource held its timer in a final field initialised at
construction:

private final Timer timer = new Timer();

Two problems follow from that.

The event source cannot be restarted. stop() calls timer.cancel() and
a cancelled java.util.Timer cannot be reused, so a subsequent start()
fails with IllegalStateException: Timer already cancelled. Restart is a
supported lifecycle - Operator.stop() / start() recreates the thread
pools for exactly this reason, and TimerEventSource creates a new
Timer inside start().

The timer thread is not a daemon and is created eagerly. Merely
constructing a PollingEventSource therefore starts a non-daemon thread
that keeps the JVM from exiting, even if the event source is never
started, and it outlives an operator that is stopped without stopping its
event sources. TimerEventSource uses new Timer(true).

The timer is now created in start() as a daemon and cleared in stop(),
matching TimerEventSource.

Adds regression tests for restart and for the daemon flag; the restart one
fails with IllegalStateException: Timer already cancelled without this
change.

Note: PerResourcePollingEventSource has a related restart limitation
because stop() calls shutdownNow() on the ScheduledExecutorService
from its configuration. That executor is supplied by the caller, so
changing its ownership semantics is a separate discussion and is left
out of this change.

Part of #3517

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@csviri
fix: create the PollingEventSource timer on start and make it a daemon
44e53a1
`PollingEventSource` held its timer in a final field initialised at
construction:

    private final Timer timer = new Timer();

Two problems follow from that.

The event source cannot be restarted. `stop()` calls `timer.cancel()` and
a cancelled `java.util.Timer` cannot be reused, so a subsequent `start()`
fails with `IllegalStateException: Timer already cancelled`. Restart is a
supported lifecycle - `Operator.stop()` / `start()` recreates the thread
pools for exactly this reason, and `TimerEventSource` creates a new
`Timer` inside `start()`.

The timer thread is not a daemon and is created eagerly. Merely
constructing a `PollingEventSource` therefore starts a non-daemon thread
that keeps the JVM from exiting, even if the event source is never
started, and it outlives an operator that is stopped without stopping its
event sources. `TimerEventSource` uses `new Timer(true)`.

The timer is now created in `start()` as a daemon and cleared in `stop()`,
matching `TimerEventSource`.

Adds regression tests for restart and for the daemon flag; the restart one
fails with `IllegalStateException: Timer already cancelled` without this
change.

Note: `PerResourcePollingEventSource` has a related restart limitation
because `stop()` calls `shutdownNow()` on the `ScheduledExecutorService`
from its configuration. That executor is supplied by the caller, so
changing its ownership semantics is a separate discussion and is left
out of this change.
Copilot AI review requested due to automatic review settings July 30, 2026 09:04
@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 30, 2026
@csviri csviri mentioned this pull request Jul 30, 2026
Correctness AI check: collection of possible issues and related PRs #3517
Closed
13 of 16 tasks
Copilot started reviewing on behalf of csviri July 30, 2026 09:05
View session
Copilot AI reviewed Jul 30, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes PollingEventSource lifecycle and JVM-exit behavior by moving java.util.Timer creation to start() (as a daemon) and clearing it in stop(), aligning its lifecycle with supported operator restart semantics and with TimerEventSource.

Changes:

  • Create the PollingEventSource timer on start() (daemon thread) and null it out on stop().
  • Add regression tests covering restart-after-stop and verifying the timer thread is daemon.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java Timer lifecycle moved to start()/stop() and daemonized to support restart and avoid blocking JVM shutdown.
operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSourceTest.java Adds regression coverage for restart behavior and daemon timer thread behavior.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSourceTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...ain/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@csviri
Apply suggestions from code review
2042020
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI review requested due to automatic review settings August 3, 2026 07:44
@csviri
csviri marked this pull request as ready for review August 3, 2026 07:44
@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 3, 2026
@openshift-ci
openshift-ci Bot requested review from metacosm and xstefank August 3, 2026 07:44
csviri
csviri commented Aug 3, 2026
View reviewed changes

@csviri csviri left a comment

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot started reviewing on behalf of csviri August 3, 2026 07:45
View session
Copilot AI reviewed Aug 3, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (2)

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java:116

  • stop() can race with a concurrent start() (e.g., dynamic deregistration/registration) because neither method is synchronized; this can lead to stop() cancelling the newly-created timer after start() assigns it. Synchronizing stop() (together with start()) makes lifecycle transitions atomic for this event source instance.
  public void stop() throws OperatorException {

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PollingEventSource.java:84

  • start() is guarded by timer != null, but timer is only assigned after getStateAndFillCache(). EventSourceManager#dynamicallyRegisterEventSource calls eventSource.start() outside its synchronized block, so concurrent start() calls on the same instance are possible; with the current ordering both callers can observe timer == null and end up creating/scheduling multiple timers/tasks (and potentially leaking the first timer when the field is overwritten). Consider guarding with isRunning() (set by super.start()) and initializing the timer before the initial cache fill so the second concurrent call returns immediately.

This issue also appears on line 116 of the same file.

  public void start() throws OperatorException {
    if (timer != null) {
      return;
    }
    super.start();

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@csviri
csviri merged commit aa8ac88 into operator-framework:main Aug 3, 2026
28 checks passed

Uh oh!

There was an error while loading. Please reload this page.

csviri added a commit to csviri/java-operator-sdk that referenced this pull request Aug 3, 2026
@csviri
fix: create the PollingEventSource timer on start and make it a daemon (
c2c7a2d
operator-framework#3523)

`PollingEventSource` held its timer in a final field initialised at
construction:

    private final Timer timer = new Timer();

Two problems follow from that.

The event source cannot be restarted. `stop()` calls `timer.cancel()` and
a cancelled `java.util.Timer` cannot be reused, so a subsequent `start()`
fails with `IllegalStateException: Timer already cancelled`. Restart is a
supported lifecycle - `Operator.stop()` / `start()` recreates the thread
pools for exactly this reason, and `TimerEventSource` creates a new
`Timer` inside `start()`.

The timer thread is not a daemon and is created eagerly. Merely
constructing a `PollingEventSource` therefore starts a non-daemon thread
that keeps the JVM from exiting, even if the event source is never
started, and it outlives an operator that is stopped without stopping its
event sources. `TimerEventSource` uses `new Timer(true)`.

The timer is now created in `start()` as a daemon and cleared in `stop()`,
matching `TimerEventSource`.

Adds regression tests for restart and for the daemon flag; the restart one
fails with `IllegalStateException: Timer already cancelled` without this
change.

Note: `PerResourcePollingEventSource` has a related restart limitation
because `stop()` calls `shutdownNow()` on the `ScheduledExecutorService`
from its configuration. That executor is supplied by the caller, so
changing its ownership semantics is a separate discussion and is left
out of this change.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@metacosm metacosm Awaiting requested review from metacosm
@xstefank xstefank Awaiting requested review from xstefank

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@csviri
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.