Skip to content

Terminate internally owned delaying-queue executors on shutdown #4977

Open

Description

@brendandburns

Problem

DefaultDelayingQueue() creates a single-thread executor and submits waitingLoop, but the executor is not retained or shut down. The inherited shutDown() only changes the queue state. Even after the waiting loop returns, the executor's non-daemon worker remains alive waiting for more executor tasks.

DefaultRateLimitingQueue() and controller construction also create executor instances for this path, so ownership and shutdown behavior need to be traced through the affected constructors.

Locations:

  • extended/src/main/java/io/kubernetes/client/extended/workqueue/DefaultDelayingQueue.java:42-52,75-117
  • extended/src/main/java/io/kubernetes/client/extended/workqueue/DefaultWorkQueue.java:99-103
  • extended/src/main/java/io/kubernetes/client/extended/workqueue/DefaultRateLimitingQueue.java:26-36
  • extended/src/main/java/io/kubernetes/client/extended/controller/builder/DefaultControllerBuilder.java

Reproduction

Create a default delaying or rate-limiting queue, then shut it down. Observe that the executor worker stays alive after the waiting loop exits; repeated queue creation/shutdown leaks threads and can prevent JVM termination.

Impact

Thread leaks and incomplete application shutdown, especially when controllers are recreated. Suggested priority: medium.

Requested fix and acceptance criteria

  • Track and terminate internally owned executors during queue shutdown.
  • Wake/cancel the waiting task promptly instead of waiting for an arbitrarily distant delayed item's deadline.
  • Explicitly preserve/document ownership semantics for caller-supplied executors; do not unexpectedly terminate unrelated work on shared executors.
  • Cover both default queue constructors and controller-created queues where relevant.
  • Add bounded regression tests proving task/executor termination, idempotent shutdown, and correct handling of caller-supplied executors. Avoid leaking test executors.

Agent instructions

Implement a focused fix, run relevant tests, and open a pull request referencing and closing this issue. Follow the repository's PR template and contribution conventions.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions