Skip to content

Commit d308262

Browse files
committed
Mark instructions as cleaned up in the GRPC data channel if processing an instruction fails.
1 parent 96e79cb commit d308262

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

sdks/python/apache_beam/runners/worker/data_plane.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def _clean_receiving_queue(self, instruction_id):
502502
instruction_id cannot be reused for new queue.
503503
"""
504504
with self._receive_lock:
505-
self._received.pop(instruction_id)
505+
self._received.pop(instruction_id, None)
506506
self._cleaned_instruction_ids[instruction_id] = True
507507
while len(self._cleaned_instruction_ids) > _MAX_CLEANED_INSTRUCTIONS:
508508
self._cleaned_instruction_ids.popitem(last=False)
@@ -787,6 +787,12 @@ def close(self):
787787
"""Close all channels that this factory owns."""
788788
raise NotImplementedError(type(self))
789789

790+
def cleanup(self, instruction_id):
791+
# type: (str) -> None
792+
793+
"""Clean up resources for a given instruction."""
794+
pass
795+
790796

791797
class GrpcClientDataChannelFactory(DataChannelFactory):
792798
"""A factory for ``GrpcClientDataChannel``.
@@ -855,6 +861,11 @@ def close(self):
855861
channel.close()
856862
self._data_channel_cache.clear()
857863

864+
def cleanup(self, instruction_id):
865+
# type: (str) -> None
866+
for channel in self._data_channel_cache.values():
867+
channel._clean_receiving_queue(instruction_id)
868+
858869

859870
class InMemoryDataChannelFactory(DataChannelFactory):
860871
"""A singleton factory for ``InMemoryDataChannel``."""

sdks/python/apache_beam/runners/worker/sdk_worker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ def discard(self, instruction_id, exception):
568568

569569
# Perform the shutdown while not holding the lock.
570570
processor.shutdown()
571+
self.data_channel_factory.cleanup(instruction_id)
571572

572573
def release(self, instruction_id):
573574
# type: (str) -> None

0 commit comments

Comments
 (0)