Skip to content

Remove dead Admin#finalizer, fix cascading admin spec failures#842

Merged
mensfeld merged 1 commit intomasterfrom
fix/admin-finalizer-cleanup
Mar 24, 2026
Merged

Remove dead Admin#finalizer, fix cascading admin spec failures#842
mensfeld merged 1 commit intomasterfrom
fix/admin-finalizer-cleanup

Conversation

@mensfeld
Copy link
Member

Summary

  • Remove dead Admin#finalizer instance method that captures self and could never work as a GC finalizer (same cleanup as Register Rdkafka::Consumer finalizer #841 did for Consumer)
  • Fix cascading test failures in admin specs by replacing the after block with around/ensure — leaked handles are now cleared from the registry after each test, so a single timeout or broker error no longer poisons all subsequent tests
  • Update CHANGELOG with Register Rdkafka::Consumer finalizer #841 attribution (jturkel)

Context

PR #841 (merged) fixed the missing Consumer finalizer registration and removed the dead Consumer#finalizer method. Admin had 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 the after block's expect(REGISTRY).to be_empty to fail on every subsequent test. The around/ensure pattern checks for leaks but always clears the registry, isolating failures.

Test plan

  • CI passes with default random seed
  • Verify the cascading failure is fixed (seed 6333 should no longer cascade)

- 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)
@mensfeld mensfeld requested a review from Copilot March 24, 2026 12:16
@mensfeld mensfeld merged commit 3fbebd0 into master Mar 24, 2026
98 checks passed
@mensfeld mensfeld deleted the fix/admin-finalizer-cleanup branch March 24, 2026 12:17
Copy link
Contributor

Copilot AI left a 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 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 after cleanup assertions with an around/ensure that always clears leaked admin handle registries between examples.
  • Remove dead Admin#finalizer method (finalization is handled via NativeKafka#finalizer).
  • Add an Unreleased 0.25.3 section 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.

Comment on lines +28 to +41
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(", ")}"
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

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).

Suggested change
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(", ")}"

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants