You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "lhotari (via GitHub)" <gi...@apache.org> on 2026/04/08 14:29:47 UTC

[PR] [fix][test] Fix thread resource leaks in tests and PrometheusMetricsProvider [pulsar]

lhotari opened a new pull request, #25487:
URL: https://github.com/apache/pulsar/pull/25487

   ### Motivation
   
   Thread leak detection in CI ([run #24135406928](https://github.com/apache/pulsar/actions/runs/24135406928)) revealed several thread resource leaks across multiple test classes and one production code issue. This PR addresses the most impactful and fixable leaks.
   
   ### Modifications
   
   **Production code fix:**
   - **PrometheusMetricsProvider.stop()**: The `ScheduledExecutorService` created in `start()` was never shut down in `stop()`, leaking `metrics-*` threads. Added `MoreExecutors.shutdownAndAwaitTermination()` call.
   
   **Test code fixes:**
   - **BookKeeperClusterTestCase**: Replaced bare `executor.shutdownNow()` with `MoreExecutors.shutdownAndAwaitTermination()` to ensure cached thread pool threads have time to terminate. This reduced leaked threads in auditor test groups from ~205 to ~27 (remaining are BookKeeper bookie internal threads).
   - **TransactionMetadataStoreProviderTest**: Added `@AfterMethod` to close the `TransactionMetadataStore` which was created in `@BeforeMethod` but never closed, leaking `txn-topic-threads-OrderedExecutor` threads.
   - **AuthenticationProviderAthenzTest**: Added `@AfterClass` to close the `AuthenticationProviderAthenz` instance which was created in `@BeforeClass` but never closed.
   
   ### Verifying this change
   
   This change is already covered by existing tests. Each fix was verified locally by running the affected test with `THREAD_LEAK_DETECTOR_WAIT_MILLIS=10000`:
   - `TestPrometheusMetricsProvider` — no thread leaks after fix (was 5)
   - `AuditorBookieTest` — reduced from 205 to 27 leaked threads (remaining are BK bookie internals)
   - `TransactionMetadataStoreProviderTest` — no thread leaks after fix (was 6)
   - `AuthenticationProviderAthenzTest` — 1 remaining leak from Athenz library singleton (not fixable from Pulsar side)
   
   ### Does this pull request potentially affect one of the following parts:
   
   - [ ] Dependencies (add or upgrade a dependency)
   - [ ] The public API
   - [ ] The schema
   - [ ] The default values of configurations
   - [ ] The threading model
   - [ ] The binary protocol
   - [ ] The REST endpoints
   - [ ] The admin CLI options
   - [ ] The metrics
   - [ ] Anything that affects deployment


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [fix][test] Fix thread resource leaks in tests and PrometheusMetricsProvider [pulsar]

Posted by "merlimat (via GitHub)" <gi...@apache.org>.
merlimat merged PR #25487:
URL: https://github.com/apache/pulsar/pull/25487


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org