Skip to content

Fix Producer.purge() ignoring boolean flags on big-endian platforms - #2345

Open
Devarsh Patel (Devarsh010) wants to merge 1 commit into
masterfrom
fix-purge-big-endian
Open

Fix Producer.purge() ignoring boolean flags on big-endian platforms#2345
Devarsh Patel (Devarsh010) wants to merge 1 commit into
masterfrom
fix-purge-big-endian

Conversation

@Devarsh010

Copy link
Copy Markdown
Member

Producer.purge() parsed its in_queue, in_flight and blocking arguments with PyArg_ParseTupleAndKeywords's "|bbb" format , which is the 1-byte "b" (unsigned char) format into 4-byte int targets pre-initialised to 1. "b" writes a single byte, which on little-endian lands on the low byte (so it happens to work) but on big-endian lands on the high byte, leaving the int as 0x00000001. The flags can therefore never be set to False on big-endian, so purge(in_queue=False) purges the queue anyway.
Fixed by using the "p" (boolean predicate → int) format, which is the correct format for these bool-typed arguments and produces identical results on little-endian. This is the only "b"-format PyArg call in the C sources.
The existing tests/test_Producer.py::test_purge already covers this: it asserts purge(in_queue=False) does not purge, which fails deterministically on big-endian before this change and passes after. Validated on a native s390x host (built against librdkafka.redist 2.15.0): before the fix test_purge fails, after it passes; little-endian behaviour is unchanged.

Copilot AI lite review requested due to automatic review settings September 3, 2026 07:56
@confluent-cla-assistant

Copy link
Copy Markdown

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The blocking flag appears to be applied with inverted semantics (blocking=True sets RD_KAFKA_PURGE_F_NON_BLOCKING), which contradicts the documented behavior and should be corrected.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR fixes Producer.purge() boolean keyword argument parsing so in_queue, in_flight, and blocking can be reliably set to False on big-endian platforms by switching from the 1-byte "b" parser format to the boolean-predicate "p" format.

Changes:

  • Update Producer.purge() argument parsing to use "|ppp" and document the endianness issue in-code.
  • Add a changelog entry describing the big-endian behavior fix.
File summaries
File Description
src/confluent_kafka/src/Producer.c Switches purge() kwarg parsing to "p" booleans and adds rationale comment.
CHANGELOG.md Documents the Producer.purge() big-endian boolean parsing fix.
Review details

Suppressed comments (1)

src/confluent_kafka/src/Producer.c:1043

  • The blocking argument’s semantics appear inverted: the docstring says blocking=False should not wait, but the code sets RD_KAFKA_PURGE_F_NON_BLOCKING when blocking is true. With the bool parsing fixed, this mismatch is now reliably observable on all platforms.
        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ppp", kws, &in_queue,
                                         &in_flight, &blocking))
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread CHANGELOG.md
- Use `asyncio.get_running_loop()` instead of `asyncio.get_event_loop()` to avoid creating a new event loop and raise an error in case a loop isn't available (@AlexCai26, #2339).
- Fix `Producer.purge()` ignoring its `in_queue`, `in_flight` and `blocking`
arguments on big-endian platforms (e.g. s390x). They were parsed with the
1-byte `"b"` format into 4-byte `int` targets, so on big-endian the value
Comment on lines +1037 to +1041
/* Use "p" (bool predicate -> int), not "b" (one byte): the targets are
* 4-byte ints, so "b" stores a single byte, which lands on the low byte
* on little-endian but the high byte on big-endian. There the flags,
* pre-initialised to 1, could never be cleared, so e.g. in_queue=False
* was ignored and the queue was purged anyway. */
@sonarqube-confluent

Copy link
Copy Markdown

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.

2 participants