Skip to content

Conversation

@fangnx
Copy link
Member

@fangnx fangnx commented Nov 12, 2025

What

Bug:

FIx:

  • Disable GC via gc.disable() in tests that make fire-and-forget calls

Checklist

  • Contains customer facing changes? Including API/behavior changes
  • Did you add sufficient unit test and/or integration test coverage for this PR?
    • If not, please explain why it is not required

References

JIRA: https://confluentinc.atlassian.net/browse/NONJAVACLI-4105

Test & Review

Open questions / Follow-ups

Copilot AI review requested due to automatic review settings November 12, 2025 04:52
@fangnx fangnx requested review from a team and MSeal as code owners November 12, 2025 04:52
@confluent-cla-assistant
Copy link

🎉 All Contributor License Agreements have been signed. Ready to merge.
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

Copy link

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 addresses a segmentation fault issue in Admin tests by disabling Python's garbage collector during callback execution in librdkafka's background threads. The fix prevents AdminClient objects from being destroyed by the garbage collector while running in librdkafka's threads, which is forbidden by the library.

Key Changes:

  • Added garbage collector disabling/enabling logic around callback execution in multiple admin result handlers
  • Removed extraneous blank lines for code cleanup

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 138 to 140
import gc
gc_was_enabled = gc.isenabled()
gc.disable()
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

Importing gc inside each callback function creates unnecessary overhead when these callbacks are invoked repeatedly. Consider moving the import gc statement to the module level at the top of the file to avoid repeated import lookups.

Copilot uses AI. Check for mistakes.
Comment on lines +238 to +236
# Disable GC during callback to prevent AdminClient destruction from librdkafka thread.
# This callback runs in librdkafka's background thread, and if GC runs here, it may
# try to destroy AdminClient objects, which librdkafka forbids from its own threads.
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

This detailed explanation of why GC is disabled should be added to all other callback methods that use the same pattern. Currently, only _make_consumer_group_offsets_result has this documentation, while _make_topics_result, _make_resource_result, _make_consumer_groups_result, _make_acls_result, _make_futmap_result_from_list, and _make_futmap_result lack explanation for the same GC disabling logic.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good point by copilot. Maybe we put to desription at the import and a small comment at disable saying see import comment for preventing null resource segfault errors?

Copy link
Member Author

Choose a reason for hiding this comment

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

good point!

"""
try:
import gc

Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

[nitpick] The blank line at 237 between the import statement and the explanatory comment is inconsistent with the formatting in other methods where the GC setup code follows immediately after the import. Consider removing this blank line for consistency.

Suggested change

Copilot uses AI. Check for mistakes.
@fangnx fangnx changed the title WIP: fix segfault issue in Admin tests Fix the intermittent segfault issue due to GC in Admin tests Nov 12, 2025
Comment on lines +238 to +236
# Disable GC during callback to prevent AdminClient destruction from librdkafka thread.
# This callback runs in librdkafka's background thread, and if GC runs here, it may
# try to destroy AdminClient objects, which librdkafka forbids from its own threads.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good point by copilot. Maybe we put to desription at the import and a small comment at disable saying see import comment for preventing null resource segfault errors?

@fangnx fangnx requested a review from MSeal November 12, 2025 23:50
MSeal
MSeal previously approved these changes Nov 13, 2025
@sonarqube-confluent
Copy link

Quality Gate failed Quality Gate failed

Failed conditions
2.3% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants