damccorm opened a new pull request, #41144:
URL: https://github.com/apache/beam/pull/41144

   ### Summary
   Fixes flaky `RecordingManagerTest.test_record_pipeline` failure 
(`self.assertFalse(rm.record_pipeline())` returning `True`) in `PreCommit 
Python Runners` ([run 
42630955737](https://github.com/apache/beam/actions/runs/42630955737)).
   
   ### Root Cause
   In `is_background_caching_job_needed`, `job.is_done() or job.is_running()` 
was evaluated across two separate acquisitions of `job._result_lock`. 
Additionally, `BackgroundCachingJob.is_done()` unconditionally called 
`self._should_end_condition_checker()` (which invokes 
`SizeLimiter.is_triggered()` -> `rm.describe()`) while holding 
`self._result_lock` even when `self._pipeline_result.state` was `RUNNING`. When 
the background `_condition_checker` thread triggered concurrently and blocked 
on `self._result_lock` in `self.cancel()`, `job.is_done()` returned `False` 
(seeing `state == RUNNING`), released `self._result_lock`, and handed the lock 
to `self.cancel()`, which transitioned `state` to `CANCELLED` before 
`job.is_running()` ran—causing `job.is_running()` to also return `False` and 
`rm.record_pipeline()` to start a second background caching job.
   
   ### Fix
   - Add `BackgroundCachingJob.is_done_or_running()` so `is_done() or 
is_running()` is checked atomically under `self._result_lock` in 
`is_background_caching_job_needed`.
   - Short-circuit `BackgroundCachingJob.is_done()` so 
`self._should_end_condition_checker()` is only evaluated when `state is 
PipelineState.CANCELLING`.
   - Reset the interactive environment (`ie.new_env()`) in 
`RecordingManagerTest.setUp`.
   
   ### Verification
   - Triggered `beam_PreCommit_Python_Runners.yml` workflow run on branch: 
[`42734784434`](https://github.com/apache/beam/actions/runs/42734784434)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to