This is an automated email from the ASF dual-hosted git repository.

shunping pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 1ca1fafcd62 Fix SubprocessServer cache thread-safety and test 
isolation (#38501)
1ca1fafcd62 is described below

commit 1ca1fafcd62b0e3f1bd6a071842cab7566366d1c
Author: Shunping Huang <[email protected]>
AuthorDate: Sun May 17 07:41:18 2026 -0400

    Fix SubprocessServer cache thread-safety and test isolation (#38501)
---
 .github/trigger_files/beam_PostCommit_Python_Versions.json |  4 ++++
 sdks/python/apache_beam/transforms/external_test.py        |  8 +++++++-
 sdks/python/apache_beam/utils/subprocess_server.py         | 11 ++++++-----
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/.github/trigger_files/beam_PostCommit_Python_Versions.json 
b/.github/trigger_files/beam_PostCommit_Python_Versions.json
new file mode 100644
index 00000000000..a975cd1cd10
--- /dev/null
+++ b/.github/trigger_files/beam_PostCommit_Python_Versions.json
@@ -0,0 +1,4 @@
+{
+  "comment": "Modify this file in a trivial way to cause this test suite to 
run",
+  "revision": 1
+}
diff --git a/sdks/python/apache_beam/transforms/external_test.py 
b/sdks/python/apache_beam/transforms/external_test.py
index 137c92861ed..0af89367fcc 100644
--- a/sdks/python/apache_beam/transforms/external_test.py
+++ b/sdks/python/apache_beam/transforms/external_test.py
@@ -799,7 +799,13 @@ class JavaClassLookupPayloadBuilderTest(unittest.TestCase):
 
 class JavaJarExpansionServiceTest(unittest.TestCase):
   def setUp(self):
-    SubprocessServer._cache._live_owners = set()
+    # Temporarily override _live_owners with an empty set for this test,
+    # preventing contamination of the process-wide global cache and avoiding
+    # side effects on other tests.
+    patcher = mock.patch.object(
+        SubprocessServer._cache, '_live_owners', new=set())
+    patcher.start()
+    self.addCleanup(patcher.stop)
 
   def test_classpath(self):
     with tempfile.TemporaryDirectory() as temp_dir:
diff --git a/sdks/python/apache_beam/utils/subprocess_server.py 
b/sdks/python/apache_beam/utils/subprocess_server.py
index fed5ee591bc..d21cb486b8f 100644
--- a/sdks/python/apache_beam/utils/subprocess_server.py
+++ b/sdks/python/apache_beam/utils/subprocess_server.py
@@ -78,13 +78,14 @@ class _SharedCache:
     self._counter = 0
 
   def _next_id(self):
-    with self._lock:
-      self._counter += 1
-      return self._counter
+    # Caller must hold self._lock.
+    self._counter += 1
+    return self._counter
 
   def register(self):
-    owner = self._next_id()
-    self._live_owners.add(owner)
+    with self._lock:
+      owner = self._next_id()
+      self._live_owners.add(owner)
     return owner
 
   def purge(self, owner):

Reply via email to