Skip to content

KAFKA-20423: Fix flakiness of testWakeupWithFetchDataAvailable#22364

Open
chickenchickenlove wants to merge 2 commits into
apache:trunkfrom
chickenchickenlove:KAFKA-20423
Open

KAFKA-20423: Fix flakiness of testWakeupWithFetchDataAvailable#22364
chickenchickenlove wants to merge 2 commits into
apache:trunkfrom
chickenchickenlove:KAFKA-20423

Conversation

@chickenchickenlove
Copy link
Copy Markdown
Contributor

Description

I didn't reproduce it in my local.
This PR is based on the specific assumptions and fix non-deterministic path caused by it.

  1. The foreground test thread puts the fetch response into MockClient.responses via respondFrom(...).
  2. The heartbeat thread enters MockClient.poll() first.
  3. The heartbeat thread removes the fetch response from the queue by calling responses.poll().
  4. However, it gets descheduled before calling response.onComplete().
  5. The foreground thread calls client.poll(0, ...), but since the response queue is empty, it completes nothing and returns.
  6. consumer.wakeup() is called.
  7. The first consumer.poll(Duration.ZERO) immediately throws WakeupException from maybeTriggerWakeup().
  8. consumer.position(tp0) already has a valid position of 0, so it returns 0 directly without performing a network poll.
  9. The next consumer.poll(Duration.ZERO) also returns empty because the response is not yet in pendingCompletion and not in the FetchBuffer either.
  10. After that, the heartbeat thread wakes up and calls response.onComplete(), but by then the assertion has already
    failed.

Although I didn't reproduce it in my local, this scenario make sense to me.
Given this, this PR applies the change, and I plan to monitor the CI trend afterward to confirm whether the flakiness is resolved.

@github-actions github-actions Bot added triage PRs from the community consumer tests Test fixes (including flaky tests) clients small Small PRs labels May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clients consumer small Small PRs tests Test fixes (including flaky tests) triage PRs from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant