Skip to content

Commit 12325c0

Browse files
authored
Only try to update sensors fetch lag if the unpacked list contains elements (#2158)
Previously, if the `unpacked` list was empty, the call to `unpacked[-1]` would throw an `IndexError: list index out of range`
1 parent b090b21 commit 12325c0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

kafka/consumer/fetcher.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,9 @@ def _parse_fetched_data(self, completed_fetch):
817817
position)
818818
unpacked = list(self._unpack_message_set(tp, records))
819819
parsed_records = self.PartitionRecords(fetch_offset, tp, unpacked)
820-
last_offset = unpacked[-1].offset
821-
self._sensors.records_fetch_lag.record(highwater - last_offset)
820+
if unpacked:
821+
last_offset = unpacked[-1].offset
822+
self._sensors.records_fetch_lag.record(highwater - last_offset)
822823
num_bytes = records.valid_bytes()
823824
records_count = len(unpacked)
824825
elif records.size_in_bytes() > 0:

0 commit comments

Comments
 (0)