Stellarhold170NT opened a new pull request, #24377:
URL: https://github.com/apache/kafka/pull/24377

   ### Summary
   
   `AbstractHeartbeatRequestManager.onErrorResponse()` invokes 
`membershipManager().transitionToFenced()` unconditionally when a heartbeat 
response completes with `FENCED_MEMBER_EPOCH` (line 446) or `UNKNOWN_MEMBER_ID` 
(line 455). A heartbeat response for a request already in flight can complete 
after the member has transitioned to `STALE` (max.poll.interval.ms expired) or 
`FATAL`, and two pipelined heartbeat responses can both carry the fence error.
   
   `transitionToFenced()` early-returns only for `PREPARE_LEAVING`, `LEAVING` 
and `UNSUBSCRIBED`. The `MemberState` transition table 
(`FENCED.previousValidStates = [JOINING, STABLE, RECONCILING, ACKNOWLEDGING, 
PREPARE_LEAVING, LEAVING]`) therefore rejects `STALE->FENCED` and 
`FATAL->FENCED`: `transitionTo()` throws `IllegalStateException` inside the 
`ConsumerNetworkThread` response handler, which swallows `Throwable` per 
`runOnce` iteration, so the rest of that poll batch of completed responses is 
dropped (futures leak to the event reaper and fence handling is skipped). For 
an already-`FENCED` member the equals-transition passes and the whole release 
block re-runs, scheduling `signalPartitionsLost` (`onPartitionsLost`) a second 
time for the same partitions.
   
   This change adds early-returns for `STALE`, `FATAL` and already-`FENCED`, so 
a late or duplicate fence error for an in-flight heartbeat is ignored instead 
of throwing or re-releasing the assignment. Fencing from an active state (the 
normal path) is unchanged.
   
   ### Testing
   
   - Minimal state-machine harness driving `ConsumerMembershipManager` directly 
(4 scenarios), run against the unpatched tree at cc3308bb: STALE + late fence 
error -> `IllegalStateException: Invalid state transition from STALE to 
FENCED`; FATAL + late fence error -> `IllegalStateException: Invalid state 
transition from FATAL to FENCED`; duplicate fence error -> `onPartitionsLost` 
scheduled twice. All three manifestations are fixed by this patch (the 
duplicate now schedules exactly once).
   - `ConsumerMembershipManagerTest` (93), 
`ConsumerHeartbeatRequestManagerTest` (73), `ShareHeartbeatRequestManagerTest` 
(46) and `StreamsGroupHeartbeatRequestManagerTest` (272) — which run the shared 
`AbstractHeartbeatRequestManagerTest` cases, the abstract base class itself not 
being directly runnable — pass against the patched tree: **484 tests, 0 
failures, 0 errors**. A grep of `clients/src/test` shows no existing test 
exercises fence-on-STALE, fence-on-FATAL or double-fencing.
   - Known secondary defect intentionally left untouched (needs its own fix): 
`ConsumerMembershipManager.isLeavingGroup()` returns false for a dynamic member 
using `REMAIN_IN_GROUP` while in `LEAVING`, so the 
`AbstractHeartbeatRequestManager.poll()` expired-poll-timer branch (line 172) 
re-enters `transitionToSendingLeaveGroup(true)` from `LEAVING` -> 
`PREPARE_LEAVING`, another illegal transition.
   - A JIRA issue should be filed for tracking; no JIRA id was available to the 
automation that prepared this change.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to