Uploaded image for project: 'Red Hat OpenStack Services on OpenShift'
  1. Red Hat OpenStack Services on OpenShift
  2. OSPRH-26203

Threading backend: ensure ThreadGroup.thread_done() is called automatically on thread completion.

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major Major
    • None
    • None
    • python-oslo-service
    • None
    • Sprint 14
    • 1

      Problem

      In the current threading backend, `ThreadGroup.thread_done()` is never called automatically when a thread completes.
      As a result, completed threads can remain in the thread group’s internal list until an explicit wait or stop occurs.

      This differs from the eventlet backend behavior and can lead to unbounded growth of the thread list in long-lived services.

      Root cause

      `thread_done()` exists for API parity with the eventlet backend but was never wired into the thread lifecycle in the threading backend.

      Solution

      • Wrap the thread callback in a `try/finally` block so `thread_done(threading.current_thread())` is always invoked on thread completion (normal exit or exception).
      • Update `_wait_threads()` to avoid holding the lock while joining threads, preventing potential deadlocks when `thread_done()` is called from the finishing thread.
      • Add unit tests covering:
      • Normal thread completion
      • Thread termination via exception
      • Multiple concurrent threads
      • `waitall()` behavior without deadlock

      Impact

      • Restores behavioral parity with the eventlet backend
      • Prevents thread list leaks in long-running services
      • Makes thread lifecycle management safer and more predictable

              mbollo@redhat.com Daniel Mats Niklas Bengtsson
              mbollo@redhat.com Daniel Mats Niklas Bengtsson
              rhos-dfg-pidone
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: