@@ -289,7 +289,9 @@ async def _run_loop(self):
289289 or num_offsets_not_committed > 1
290290 and time .monotonic () >= last_commit_time + self ._max_time_before_commit
291291 ):
292- num_offsets_not_committed = await _commit_handled_events (self ._outstanding_offsets , committer )
292+ num_offsets_not_committed = await _commit_handled_events (
293+ self ._outstanding_offsets , committer , self .logger
294+ )
293295 events_handled_since_commit = 0
294296 last_commit_time = time .monotonic ()
295297 # Due to the last event not being garbage collected, we tolerate a single unhandled event
@@ -300,7 +302,9 @@ async def _run_loop(self):
300302 break
301303 except queue .Empty :
302304 pass
303- num_offsets_not_committed = await _commit_handled_events (self ._outstanding_offsets , committer )
305+ num_offsets_not_committed = await _commit_handled_events (
306+ self ._outstanding_offsets , committer , self .logger
307+ )
304308 events_handled_since_commit = 0
305309 last_commit_time = time .monotonic ()
306310 if event is None :
@@ -318,7 +322,7 @@ async def _run_loop(self):
318322 if event is _termination_obj :
319323 # We can commit all at this point because termination of
320324 # all downstream steps completed successfully.
321- await _commit_handled_events (self ._outstanding_offsets , committer , commit_all = True )
325+ await _commit_handled_events (self ._outstanding_offsets , committer , self . logger , commit_all = True )
322326 self ._termination_future .set_result (termination_result )
323327 except BaseException as ex :
324328 if self .logger :
@@ -510,7 +514,7 @@ async def await_termination(self):
510514 return await self ._loop_task
511515
512516
513- async def _commit_handled_events (outstanding_offsets_by_qualified_shard , committer , commit_all = False ):
517+ async def _commit_handled_events (outstanding_offsets_by_qualified_shard , committer , logger , commit_all = False ):
514518 num_offsets_not_handled = 0
515519 if not commit_all :
516520 gc .collect ()
@@ -530,7 +534,12 @@ async def _commit_handled_events(outstanding_offsets_by_qualified_shard, committ
530534 num_to_clear += 1
531535 if last_handled_offset is not None :
532536 path , shard_id = qualified_shard
533- await committer (QualifiedOffset (path , shard_id , last_handled_offset ))
537+ try :
538+ await committer (QualifiedOffset (path , shard_id , last_handled_offset ))
539+ except BaseException :
540+ if logger :
541+ logger .error (f"Failed to commit offsets due to error: { traceback .format_exc ()} " )
542+ return num_offsets_not_handled + num_to_clear
534543 outstanding_offsets_by_qualified_shard [qualified_shard ] = offsets [num_to_clear :]
535544 return num_offsets_not_handled
536545
@@ -601,7 +610,9 @@ async def _run_loop(self):
601610 or num_offsets_not_handled > 0
602611 and time .monotonic () >= last_commit_time + self ._max_time_before_commit
603612 ):
604- num_offsets_not_handled = await _commit_handled_events (self ._outstanding_offsets , committer )
613+ num_offsets_not_handled = await _commit_handled_events (
614+ self ._outstanding_offsets , committer , self .logger
615+ )
605616 events_handled_since_commit = 0
606617 last_commit_time = time .monotonic ()
607618 # In case we can't block because there are outstanding events
@@ -611,7 +622,9 @@ async def _run_loop(self):
611622 break
612623 except TimeoutError :
613624 pass
614- num_offsets_not_handled = await _commit_handled_events (self ._outstanding_offsets , committer )
625+ num_offsets_not_handled = await _commit_handled_events (
626+ self ._outstanding_offsets , committer , self .logger
627+ )
615628 events_handled_since_commit = 0
616629 last_commit_time = time .monotonic ()
617630 if not event :
@@ -629,7 +642,7 @@ async def _run_loop(self):
629642 if event is _termination_obj :
630643 # We can commit all at this point because termination of
631644 # all downstream steps completed successfully.
632- await _commit_handled_events (self ._outstanding_offsets , committer , commit_all = True )
645+ await _commit_handled_events (self ._outstanding_offsets , committer , self . logger , commit_all = True )
633646 return termination_result
634647 except BaseException as ex :
635648 if self .logger :
0 commit comments