Remove dead Admin#finalizer, fix cascading admin spec failures#842
Remove dead Admin#finalizer, fix cascading admin spec failures#842
Conversation
- Remove dead `Admin#finalizer` instance method that captures `self` and could never work as a GC finalizer (matching Consumer cleanup from #841) - Replace `after` block with `around`/`ensure` in admin specs to clear leaked handles from the registry, preventing a single test timeout or broker error from cascading failures to all subsequent tests - Update CHANGELOG with PR #841 attribution (jturkel)
There was a problem hiding this comment.
Pull request overview
This PR removes an unused Rdkafka::Admin#finalizer method and hardens the admin spec cleanup so a single leaking handle can’t cause cascading failures across subsequent examples.
Changes:
- Replace
aftercleanup assertions with anaround/ensurethat always clears leaked admin handle registries between examples. - Remove dead
Admin#finalizermethod (finalization is handled viaNativeKafka#finalizer). - Add an Unreleased
0.25.3section to the CHANGELOG documenting these fixes (and #841’s consumer finalizer work attribution).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| spec/lib/rdkafka/admin_spec.rb | Switch to around/ensure leak checking and forced registry cleanup to prevent cascading spec failures. |
| lib/rdkafka/admin.rb | Remove dead #finalizer instance method. |
| CHANGELOG.md | Add 0.25.3 (Unreleased) entries covering the finalizer cleanup and spec isolation fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| registry_leaks = [ | ||
| Rdkafka::Admin::CreateTopicHandle, | ||
| Rdkafka::Admin::CreatePartitionsHandle, | ||
| Rdkafka::Admin::DescribeAclHandle, | ||
| Rdkafka::Admin::CreateAclHandle, | ||
| Rdkafka::Admin::DeleteAclHandle, | ||
| Rdkafka::Admin::ListOffsetsHandle | ||
| ].reject { |handle_class| handle_class::REGISTRY.empty? } | ||
|
|
||
| registry_leaks.each { |handle_class| handle_class::REGISTRY.clear } | ||
|
|
||
| admin.close | ||
|
|
||
| expect(registry_leaks).to be_empty, "Leaked handles in: #{registry_leaks.map(&:name).join(", ")}" |
There was a problem hiding this comment.
All these handle classes appear to share the same REGISTRY constant via inheritance from Rdkafka::AbstractHandle (none of the admin handle subclasses define their own REGISTRY). As a result, registry_leaks will either be empty or contain all listed classes, and the failure message will be misleading about which handle type actually leaked. Consider checking/clearing Rdkafka::AbstractHandle::REGISTRY once and deriving leaked types from REGISTRY.values.map(&:class).uniq (or alternatively defining per-handle REGISTRY constants if separation is intended).
| registry_leaks = [ | |
| Rdkafka::Admin::CreateTopicHandle, | |
| Rdkafka::Admin::CreatePartitionsHandle, | |
| Rdkafka::Admin::DescribeAclHandle, | |
| Rdkafka::Admin::CreateAclHandle, | |
| Rdkafka::Admin::DeleteAclHandle, | |
| Rdkafka::Admin::ListOffsetsHandle | |
| ].reject { |handle_class| handle_class::REGISTRY.empty? } | |
| registry_leaks.each { |handle_class| handle_class::REGISTRY.clear } | |
| admin.close | |
| expect(registry_leaks).to be_empty, "Leaked handles in: #{registry_leaks.map(&:name).join(", ")}" | |
| admin_handle_classes = [ | |
| Rdkafka::Admin::CreateTopicHandle, | |
| Rdkafka::Admin::CreatePartitionsHandle, | |
| Rdkafka::Admin::DescribeAclHandle, | |
| Rdkafka::Admin::CreateAclHandle, | |
| Rdkafka::Admin::DeleteAclHandle, | |
| Rdkafka::Admin::ListOffsetsHandle | |
| ] | |
| registry = Rdkafka::AbstractHandle::REGISTRY | |
| leaked_handle_classes = | |
| registry.values.map(&:class).uniq & admin_handle_classes | |
| registry.clear | |
| admin.close | |
| expect(leaked_handle_classes).to be_empty, | |
| "Leaked handles in: #{leaked_handle_classes.map(&:name).join(", ")}" |
Summary
Admin#finalizerinstance method that capturesselfand could never work as a GC finalizer (same cleanup as Register Rdkafka::Consumer finalizer #841 did forConsumer)afterblock witharound/ensure— leaked handles are now cleared from the registry after each test, so a single timeout or broker error no longer poisons all subsequent testsContext
PR #841 (merged) fixed the missing
Consumerfinalizer registration and removed the deadConsumer#finalizermethod.Adminhad the same dead method.The cascading test failure was discovered during CI for #841: with random seed 6333, a single admin test failure left a handle in the shared
REGISTRY, causing theafterblock'sexpect(REGISTRY).to be_emptyto fail on every subsequent test. Thearound/ensurepattern checks for leaks but always clears the registry, isolating failures.Test plan