Skip to content

Fix ZeroDivisionError at initial invocation of monitoring_info when there is no work yet - #39885

Open
Abacn wants to merge 1 commit into
apache:masterfrom
Abacn:fix-div-0
Open

Fix ZeroDivisionError at initial invocation of monitoring_info when there is no work yet#39885
Abacn wants to merge 1 commit into
apache:masterfrom
Abacn:fix-div-0

Conversation

@Abacn

@Abacn Abacn commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

It is found running a streaming pipeline in Python, there is an error at the beginning:

Traceback (most recent call last):
  File "...beam/sdks/python/apache_beam/runners/worker/sdk_worker.py", line 310, in _execute
    response = task()
  File "...beam/sdks/python/apache_beam/runners/worker/sdk_worker.py", line 347, in <lambda>
    lambda: self.create_worker().do_instruction(request), request)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "...beam/sdks/python/apache_beam/runners/worker/sdk_worker.py", line 671, in do_instruction
    return getattr(self, request_type)(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        getattr(request, request_type), request.instruction_id)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...beam/sdks/python/apache_beam/runners/worker/sdk_worker.py", line 762, in process_bundle_progress
    monitoring_infos = processor.monitoring_infos()
  File "...beam/sdks/python/apache_beam/runners/worker/bundle_processor.py", line 1441, in monitoring_infos
    op.monitoring_infos(transform_id, dict(tag_to_pcollection_id)))
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apache_beam/runners/worker/operations.py", line 1111, in apache_beam.runners.worker.operations.SdfProcessSizedElements.monitoring_infos
    def monitoring_infos(self, transform_id, tag_to_pcollection_id):
  File "apache_beam/runners/worker/operations.py", line 1116, in apache_beam.runners.worker.operations.SdfProcessSizedElements.monitoring_infos
    with self.lock:
  File "apache_beam/runners/worker/operations.py", line 1125, in apache_beam.runners.worker.operations.SdfProcessSizedElements.monitoring_infos
    completed = current_element_progress.fraction_completed
  File "...beam/sdks/python/apache_beam/io/iobase.py", line 1720, in fraction_completed
    return float(self._completed) / self.total_work
           ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
ZeroDivisionError: float division by zero

This is because a RestrictionProgress {'fraction': None, 'remaining': 0.0, 'completed': 0} is initialized at

  File "apache_beam/runners/worker/operations.py", line 1116, in apache_beam.runners.worker.operations.SdfProcessSizedElements.monitoring_infos
    with self.lock:
  File "apache_beam/runners/worker/operations.py", line 1119, in apache_beam.runners.worker.operations.SdfProcessSizedElements.monitoring_infos
    current_element_progress = self.current_element_progress()
  File "apache_beam/runners/worker/operations.py", line 1101, in apache_beam.runners.worker.operations.SdfProcessSizedElements.current_element_progress
    with self.lock:
  File "apache_beam/runners/worker/operations.py", line 1106, in apache_beam.runners.worker.operations.SdfProcessSizedElements.current_element_progress
    return progress.with_completed(
  File "...beam/sdks/python/apache_beam/io/iobase.py", line 1733, in with_completed
    return RestrictionProgress(
        fraction=self._fraction, remaining=self._remaining, completed=completed)

Please add a meaningful description for your change here


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @tvalentyn for label python.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@tvalentyn tvalentyn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants