Skip to content

fix: non-flexible ElectLeadersRequest V0/V1 encode/decode#3312

Merged
hindessm merged 1 commit intoIBM:mainfrom
hindessm:fix-elect-leaders-request-v1
Sep 26, 2025
Merged

fix: non-flexible ElectLeadersRequest V0/V1 encode/decode#3312
hindessm merged 1 commit intoIBM:mainfrom
hindessm:fix-elect-leaders-request-v1

Conversation

@hindessm
Copy link
Copy Markdown
Collaborator

And clean up the misleading layout/comment of the []bytes in the test:

Test layout for V2 []byte was:

	0, 0, // empty tagged fields
	0, 39, 16, 0, // timeout 10000

but, while the bytes were correct the comments were misleading as the encoding is really:

	0,            // empty tagged fields
	0, 0, 39, 16, // timeout 10000
	0, // empty tagged fields

And clean up the misleading layout/comment of the []bytes in the test

Signed-off-by: beanz <[email protected]>
Copy link
Copy Markdown
Collaborator

@dnwe dnwe left a comment

Choose a reason for hiding this comment

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

LGTM, good catch

@dnwe
Copy link
Copy Markdown
Collaborator

dnwe commented Sep 26, 2025

Aside: we probably should have a functional test for elect leaders as I feel like this has likely never properly worked?

@hindessm hindessm merged commit 8381c03 into IBM:main Sep 26, 2025
16 checks passed
@hindessm hindessm deleted the fix-elect-leaders-request-v1 branch September 26, 2025 11:08
@dnwe dnwe added the fix label Oct 3, 2025
dnwe pushed a commit that referenced this pull request Mar 20, 2026
## Why

`ElectLeaders` request/response version 1 must use the non-flexible wire
format.

That path was fixed once in #3312, but
a later refactor left the `ElectLeaders` header version selection
inconsistent with the protocol version again. As a result, a client
configured for `V2_3_0_0` can fail to decode `ElectLeaders` V1 responses
from newer brokers with:

`kafka: insufficient data to decode packet, more bytes expected`

## What

- add a functional test that covers low-version client compatibility
against newer brokers for the `ElectLeaders` V1 non-flexible path
- select `ElectLeaders` request/response header versions from the actual
protocol version instead of treating V1 as flexible

## Testing

This PR contains two commits. The first commit only adds a functional
test and is expected to fail. The second commit only contains the
protocol fix and is expected to make CI pass.

Before opening this PR, I created a draft PR in my fork to run CI and
verify that the test was actually effective.

- failing job: [FVT (PR) / Kafka
2.6.3](https://github.com/DCjanus/sarama/actions/runs/23286394025/job/67710812112)
- passing job: [FVT (PR) / Kafka
2.6.3](https://github.com/DCjanus/sarama/actions/runs/23286993578/job/67712775310)

---------

Signed-off-by: DCjanus <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants