@@ -275,6 +275,18 @@ async def process_input_stream(self, request_iterator: AsyncIterable[reduce_pb2.
275275 _LOGGER .critical (err_msg , exc_info = True )
276276 await self .global_result_queue .put (e )
277277
278+ # Cancel and await remaining tasks to suppress "never retrieved" warnings
279+ for task in self .get_tasks ():
280+ for fut in (task .future , task .consumer_future ):
281+ if fut and not fut .done ():
282+ fut .cancel ()
283+ for fut in (task .future , task .consumer_future ):
284+ if fut :
285+ try :
286+ await fut
287+ except (asyncio .CancelledError , BaseException ):
288+ pass
289+
278290 async def write_to_global_queue (
279291 self , input_queue : NonBlockingIterator , output_queue : NonBlockingIterator , window
280292 ):
@@ -284,10 +296,19 @@ async def write_to_global_queue(
284296 to the global result queue
285297 """
286298 reader = input_queue .read_iterator ()
287- async for msg in reader :
288- res = reduce_pb2 .ReduceResponse .Result (keys = msg .keys , value = msg .value , tags = msg .tags )
289- out = reduce_pb2 .ReduceResponse (result = res , window = window )
290- await output_queue .put (out )
299+ try :
300+ async for msg in reader :
301+ res = reduce_pb2 .ReduceResponse .Result (
302+ keys = msg .keys , value = msg .value , tags = msg .tags
303+ )
304+ out = reduce_pb2 .ReduceResponse (result = res , window = window )
305+ await output_queue .put (out )
306+ except Exception as e :
307+ # Using Exception (not BaseException) so that asyncio.CancelledError
308+ # (a BaseException subclass in Python 3.9+) propagates normally
309+ # when the task is cancelled during shutdown.
310+ _LOGGER .critical ("Error serializing reduce result: %s" , e , exc_info = True )
311+ await output_queue .put (e )
291312
292313 def clean_background (self , task ):
293314 """
0 commit comments