Skip to content

Make SubprocessServer shared cache purging idempotent#38455

Merged
shunping merged 2 commits into
apache:masterfrom
shunping:fix-purge
May 12, 2026
Merged

Make SubprocessServer shared cache purging idempotent#38455
shunping merged 2 commits into
apache:masterfrom
shunping:fix-purge

Conversation

@shunping
Copy link
Copy Markdown
Collaborator

@shunping shunping commented May 12, 2026

Avoid raising ValueError during atexit shutdown when a cached subprocess server was already cleaned up earlier. Right now, such exception is already ignored (from the log below).

Example traceback (https://github.com/apache/beam/actions/runs/25705764624/job/75475412939):

Exception ignored in atexit callback: <bound method StopOnExitJobServer.stop of <apache_beam.runners.portability.job_server.StopOnExitJobServer object at 0x7f60831f4da0>>
Traceback (most recent call last):
  File "/runner/_work/beam/beam/sdks/python/test-suites/tox/py312/build/srcs/sdks/python/target/.tox-py312/py312/lib/python3.12/site-packages/apache_beam/runners/portability/job_server.py", line 98, in stop
    self._job_server.stop()
  File "/runner/_work/beam/beam/sdks/python/test-suites/tox/py312/build/srcs/sdks/python/target/.tox-py312/py312/lib/python3.12/site-packages/apache_beam/runners/portability/job_server.py", line 132, in stop
    return self._server.stop()
           ^^^^^^^^^^^^^^^^^^^
  File "/runner/_work/beam/beam/sdks/python/test-suites/tox/py312/build/srcs/sdks/python/target/.tox-py312/py312/lib/python3.12/site-packages/apache_beam/utils/subprocess_server.py", line 254, in stop
    self.stop_process()
  File "/runner/_work/beam/beam/sdks/python/test-suites/tox/py312/build/srcs/sdks/python/target/.tox-py312/py312/lib/python3.12/site-packages/apache_beam/utils/subprocess_server.py", line 259, in stop_process
    self._cache.purge(self._owner_id)
  File "/runner/_work/beam/beam/sdks/python/test-suites/tox/py312/build/srcs/sdks/python/target/.tox-py312/py312/lib/python3.12/site-packages/apache_beam/utils/subprocess_server.py", line 94, in purge
    raise ValueError(f"{owner} not in {self._live_owners}")
ValueError: 267 not in set()
Exception ignored in atexit callback: <bound method StopOnExitJobServer.stop of <apache_beam.runners.portability.job_server.StopOnExitJobServer object at 0x7f603aeb8ef0>>
Traceback (most recent call last):
  File "/runner/_work/beam/beam/sdks/python/test-suites/tox/py312/build/srcs/sdks/python/target/.tox-py312/py312/lib/python3.12/site-packages/apache_beam/runners/portability/job_server.py", line 98, in stop
    self._job_server.stop()
  File "/runner/_work/beam/beam/sdks/python/test-suites/tox/py312/build/srcs/sdks/python/target/.tox-py312/py312/lib/python3.12/site-packages/apache_beam/runners/portability/job_server.py", line 132, in stop
    return self._server.stop()
           ^^^^^^^^^^^^^^^^^^^
  File "/runner/_work/beam/beam/sdks/python/test-suites/tox/py312/build/srcs/sdks/python/target/.tox-py312/py312/lib/python3.12/site-packages/apache_beam/utils/subprocess_server.py", line 254, in stop
    self.stop_process()
  File "/runner/_work/beam/beam/sdks/python/test-suites/tox/py312/build/srcs/sdks/python/target/.tox-py312/py312/lib/python3.12/site-packages/apache_beam/utils/subprocess_server.py", line 259, in stop_process
    self._cache.purge(self._owner_id)
  File "/runner/_work/beam/beam/sdks/python/test-suites/tox/py312/build/srcs/sdks/python/target/.tox-py312/py312/lib/python3.12/site-packages/apache_beam/utils/subprocess_server.py", line 94, in purge
    raise ValueError(f"{owner} not in {self._live_owners}")
ValueError: 2 not in set()

@shunping shunping marked this pull request as ready for review May 12, 2026 03:28
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where subprocess servers would raise a ValueError during atexit shutdown if the cache had already been cleaned up. By making the purge operation idempotent and logging a warning instead of failing, the system now handles redundant cleanup calls gracefully, ensuring cleaner process termination.

Highlights

  • Idempotent Cache Purging: Modified the SubprocessServer cache purging logic to be idempotent, preventing ValueError exceptions during atexit shutdown.
  • Logging Improvement: Replaced the exception raise with a warning log when an owner is already purged, improving observability during shutdown sequences.
  • Test Coverage: Updated existing tests to verify idempotent behavior and added a new test case to ensure stop_process() succeeds even after the cache has been purged.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the purge method in subprocess_server.py to be idempotent, replacing a ValueError with a warning log when an owner is already purged. This change addresses issues where subprocesses are cleaned up multiple times during shutdown or test teardown. The test suite has been updated to reflect this behavior and includes a new test case for verification. Feedback was provided regarding the placement of the log message within a lock block, which could lead to performance issues or deadlocks.

Comment thread sdks/python/apache_beam/utils/subprocess_server.py
@github-actions
Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @jrmccluskey 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).

Copy link
Copy Markdown
Contributor

@jrmccluskey jrmccluskey left a comment

Choose a reason for hiding this comment

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

LGTM

@shunping shunping merged commit 34c6e26 into apache:master May 12, 2026
124 of 126 checks passed
@shunping shunping deleted the fix-purge branch May 12, 2026 14:10
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