Keep the str() of group and user names until librdkafka has copied them #2434
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.48) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 545 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.377
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #2434"
general
weight: 0.35
pylaterreur
What
----
describe_consumer_groups(),describe_user_scram_credentials()anddelete_consumer_groups()pass librdkafka the UTF-8 data ofstr()of each name, and release thatstrright after taking its data. librdkafka reads the data later: after the loop for the first two, and right after the release fordelete_consumer_groups(). For an exactstr,str()returns the item itself, which the list keeps alive. For astrsubclass, such as anenum.StrEnummember, it returns a new object: the pointers dangle, and the next names reuse the same memory. On Python 3.11,describe_consumer_groups()with two such distinct group ids fails with "Duplicate groups not allowed", anddescribe_user_scram_credentials()with "Duplicate users aren't allowed in the same request". A name with a lone surrogate has no UTF-8 data at all, and the NULL pointer crashed the process.describe_consumer_groups()anddescribe_user_scram_credentials()now keep the converted strings in a list until the request has been created,delete_consumer_groups()releases each one oncerd_kafka_DeleteGroup_new()has copied it, and a name that cannot be encoded raisesUnicodeEncodeError.Checklist
------------------
- These methods no longer reject distinct
str-subclass names as duplicates, and raiseUnicodeEncodeErrorinstead of crashing. CHANGELOG entry under Unreleased.- In
tests/concurrency/test_memory_safety.py:-
test_str_of_names_kept_until_the_request_is_made, fordescribe_consumer_groups()anddescribe_user_scram_credentials(), gives two names whosestr()returns a copy whose release waits for the result of the request, which only comes once the request has been made with the names.-
test_delete_consumer_groups_copies_names_before_releasing_them: two distinct such names make a request instead of being rejected as duplicates.-
test_describe_consumer_groups_name_not_encodable_as_utf8_raisesand the same for the two other methods, each run in a subprocess like the other crash tests there.References
----------
str()copies.Test & Review
------------
| | master | this branch |
|---|---|---|
|
test_str_of_names_kept_until_the_request_is_made, 2 methods | fail on both:[False, False] == [True, True]| pass on both ||
test_delete_consumer_groups_copies_names_before_releasing_them| fails on 3.11 ("Duplicate groups not allowed"), passes on 3.14t | passes on both ||
test_*_name_not_encodable_as_utf8_raises, 3 methods | segfault on both (returncode -11) | pass on both |describe_consumer_groups()anddescribe_user_scram_credentials()released right after the conversion loop, before the request,test_str_of_names_kept_until_the_request_is_madefails for both on 3.11, while the earlier test of this PR,test_str_of_names_kept_until_all_are_converted, passed.PYTHONHASHSEED.describe_consumer_groups([Name.ALICE, Name.BOB]), withclass Name(str, enum.Enum)and__str__ = str.__str__as inenum.StrEnum, fails with "Duplicate groups not allowed", anddescribe_user_scram_credentials()with "Duplicate users aren't allowed in the same request".tests/test_Admin.pyandtests/concurrency/test_memory_safety.py(with the consumer group and SCRAM race tests): 65 passed on 3.11 and on 3.14t.tools/style-format.shon the test file andflake8pass. clang-format 18.1.3 and 21.1.8 report no new differences inAdmin.c, and gcc no warnings.Open questions / Follow-ups
--------------------------
🤖 Generated with Claude Code
https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN