damccorm opened a new pull request, #41155: URL: https://github.com/apache/beam/pull/41155
### Summary Fixes a cancellation race in `BeamEnumerableConverter.waitUntilFinish` exposed by `JdbcDriverTest.testCancelUnboundedQuery` in `PreCommit SQL` ([run 42748490968](https://github.com/apache/beam/actions/runs/42748490968)). ### Root Cause In `BeamEnumerableConverter.waitUntilFinish(PipelineResult result, AtomicBoolean cancelFlag)`, a background `BeamSqlPipelineCanceller` thread polls `cancelFlag` and calls `result.cancel()` while the main thread blocks in `result.waitUntilFinish()`. When `DirectRunner` cancels a pipeline, `TransformEvaluatorRegistry.cleanup()` races with in-flight worker threads calling `TransformEvaluatorRegistry.forApplication(...)`, which can throw `IllegalStateException("Tried to get an evaluator for a finished TransformEvaluatorRegistry")` from `result.waitUntilFinish()`. Because `waitUntilFinish` previously only called `checkNotCancelled(cancelFlag)` after `result.waitUntilFinish()` returned normally, this teardown `RuntimeException` bypassed `checkNotCancelled(cancelFlag)` instead of throwing `CancellationException("Statement canceled")`. ### Fix Catch `RuntimeException` around `result.waitUntilFinish()` in `BeamEnumerableConverter.waitUntilFinish` and call `checkNotCancelled(cancelFlag)` before rethrowing. ### Verification - Triggered `beam_PreCommit_SQL.yml` workflow run on branch: [`42822679876`](https://github.com/apache/beam/actions/runs/42822679876) -- 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]
