fix portable runner streams dying after 5min
diff --git a/sdks/python/apache_beam/runners/portability/portable_runner.py b/sdks/python/apache_beam/runners/portability/portable_runner.py index 22c3440..290a5ba 100644 --- a/sdks/python/apache_beam/runners/portability/portable_runner.py +++ b/sdks/python/apache_beam/runners/portability/portable_runner.py
@@ -21,7 +21,6 @@ import atexit import copy import functools -import itertools import logging import threading import time @@ -218,15 +217,18 @@ Iterator[beam_job_api_pb2.JobMessagesResponse]]: """Run the job""" try: + # Use a timeout only for the check below to keep it from hanging. state_stream = self.job_service.GetStateStream( beam_job_api_pb2.GetJobStateRequest(job_id=preparation_id), timeout=self.timeout) # If there's an error, we don't always get it until we try to read. # Fortunately, there's always an immediate current state published. - state_stream = itertools.chain([next(state_stream)], state_stream) + next(state_stream) + # No timeout here: it would cut these streams off while the job runs. + state_stream = self.job_service.GetStateStream( + beam_job_api_pb2.GetJobStateRequest(job_id=preparation_id)) message_stream = self.job_service.GetMessageStream( - beam_job_api_pb2.JobMessagesRequest(job_id=preparation_id), - timeout=self.timeout) + beam_job_api_pb2.JobMessagesRequest(job_id=preparation_id)) except Exception: # TODO(https://github.com/apache/beam/issues/19284): Unify preparation_id # and job_id for all runners.
diff --git a/sdks/python/apache_beam/runners/portability/portable_runner_test.py b/sdks/python/apache_beam/runners/portability/portable_runner_test.py index e781e13..d940946 100644 --- a/sdks/python/apache_beam/runners/portability/portable_runner_test.py +++ b/sdks/python/apache_beam/runners/portability/portable_runner_test.py
@@ -209,6 +209,13 @@ | beam.ParDo(AddIndex()), equal_to(expected)) + def test_job_outlives_job_server_timeout(self): + # The timeout bounds requests to the job service, not the job itself. + options = self.create_options() + options.view_as(PortableOptions).job_server_timeout = 1 + with beam.Pipeline(self.get_runner(), options) as p: + _ = p | beam.Create([5]) | beam.Map(time.sleep) + # Inherits all other tests from fn_api_runner_test.FnApiRunnerTest def test_sdf_default_truncate_when_bounded(self):