|
65 | 65 | , max_bytes_orig :: bytes() |
66 | 66 | , sleep_timeout :: integer() |
67 | 67 | , prefetch_count :: integer() |
68 | | - , last_corr_id :: corr_id() |
| 68 | + , last_corr_id :: ?undef | corr_id() |
69 | 69 | , subscriber :: ?undef | pid() |
70 | 70 | , subscriber_mref :: ?undef | reference() |
71 | 71 | , pending_acks = [] :: [offset()] |
@@ -293,16 +293,18 @@ do_debug(Pid, Debug) -> |
293 | 293 | ok. |
294 | 294 |
|
295 | 295 | handle_fetch_response(_Response, _CorrId, |
296 | | - #state{subscriber = ?undef} = State) -> |
| 296 | + #state{subscriber = ?undef} = State0) -> |
297 | 297 | %% discard fetch response when there is no (dead?) subscriber |
| 298 | + State = State0#state{last_corr_id = ?undef}, |
298 | 299 | {noreply, State}; |
299 | 300 | handle_fetch_response(_Response, CorrId1, |
300 | 301 | #state{ last_corr_id = CorrId2 |
301 | 302 | } = State) when CorrId1 =/= CorrId2 -> |
302 | 303 | {noreply, State}; |
303 | 304 | handle_fetch_response(#kpro_FetchResponse{ fetchResponseTopic_L = [TopicData] |
304 | | - }, CorrId, State) -> |
305 | | - CorrId = State#state.last_corr_id, %% assert |
| 305 | + }, CorrId, State0) -> |
| 306 | + CorrId = State0#state.last_corr_id, %% assert |
| 307 | + State = State0#state{last_corr_id = ?undef}, |
306 | 308 | #kpro_FetchResponseTopic{ topicName = Topic |
307 | 309 | , fetchResponsePartition_L = [PartitionResponse] |
308 | 310 | } = TopicData, |
@@ -478,6 +480,9 @@ maybe_send_fetch_request(#state{socket_pid = ?undef} = State) -> |
478 | 480 | maybe_send_fetch_request(#state{is_suspended = true} = State) -> |
479 | 481 | %% waiting for subscriber to re-subscribe |
480 | 482 | State; |
| 483 | +maybe_send_fetch_request(#state{last_corr_id = I} = State) when is_integer(I) -> |
| 484 | + %% Waiting for the last request |
| 485 | + State; |
481 | 486 | maybe_send_fetch_request(#state{ pending_acks = PendingAcks |
482 | 487 | , prefetch_count = PrefetchCount |
483 | 488 | } = State) -> |
@@ -575,13 +580,15 @@ fetch_valid_offset(SocketPid, BeginOffset, Topic, Partition) -> |
575 | 580 |
|
576 | 581 | %% @private Reset fetch buffer, use the last unacked offset as the next begin |
577 | 582 | %% offset to fetch data from. |
| 583 | +%% Discard onwire fetch responses by setting last_corr_id to undefined. |
578 | 584 | %% @end |
579 | 585 | -spec reset_buffer(#state{}) -> #state{}. |
580 | 586 | reset_buffer(#state{pending_acks = []} = State) -> |
581 | | - State; |
| 587 | + State#state{last_corr_id = ?undef}; |
582 | 588 | reset_buffer(#state{pending_acks = [Offset | _]} = State) -> |
583 | 589 | State#state{ begin_offset = Offset |
584 | 590 | , pending_acks = [] |
| 591 | + , last_corr_id = ?undef |
585 | 592 | }. |
586 | 593 |
|
587 | 594 | %% @private Catch noproc exit exception when making gen_server:call. |
|
0 commit comments