Skip to content

Commit 265ce8e

Browse files
committed
Invoke cleanup even if BP failed to create.
1 parent d308262 commit 265ce8e

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -559,15 +559,17 @@ def discard(self, instruction_id, exception):
559559
"""
560560
Marks the instruction id as failed shutting down the ``BundleProcessor``.
561561
"""
562+
processor = None
562563
with self._lock:
563564
self.failed_instruction_ids[instruction_id] = exception
564565
while len(self.failed_instruction_ids) > MAX_FAILED_INSTRUCTIONS:
565566
self.failed_instruction_ids.popitem(last=False)
566-
processor = self.active_bundle_processors[instruction_id][1]
567-
del self.active_bundle_processors[instruction_id]
567+
if instruction_id in self.active_bundle_processors:
568+
processor = self.active_bundle_processors.pop(instruction_id)[1]
568569

569570
# Perform the shutdown while not holding the lock.
570-
processor.shutdown()
571+
if processor:
572+
processor.shutdown()
571573
self.data_channel_factory.cleanup(instruction_id)
572574

573575
def release(self, instruction_id):
@@ -691,9 +693,9 @@ def process_bundle(
691693
instruction_id # type: str
692694
):
693695
# type: (...) -> beam_fn_api_pb2.InstructionResponse
694-
bundle_processor = self.bundle_processor_cache.get(
695-
instruction_id, request.process_bundle_descriptor_id)
696696
try:
697+
bundle_processor = self.bundle_processor_cache.get(
698+
instruction_id, request.process_bundle_descriptor_id)
697699
with bundle_processor.state_handler.process_instruction_id(
698700
instruction_id, request.cache_tokens):
699701
with self.maybe_profile(instruction_id):

0 commit comments

Comments
 (0)