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

   Note: this PR was auto-generated by tooling. Before moving it out of draft, 
the author has done a full review of the PR, specifically evaluating it on the 
following criteria:
   
   - The PR is an appropriate fix for the issue (e.g. we're not changing a test 
to avoid a bug)
   - The PR is a simple fix to the issue (e.g. we're not adding infra when we 
could just modify a test)
   - The PR is not covering for other problems (e.g. if we're bumping timeouts, 
it is not because we're covering for a performance problem)
     
   Full details of the methodology of generation and review can be found here - 
https://docs.google.com/document/d/14lj7ECVov4T4EdwmIzNlWrRGE3lLDMOwX5xUMGzaLoc/edit?usp=sharing
   
   If you have concerns with the PR or with the underlying methodology used to 
generate this, please comment below - they will be addressed by the author not 
the tooling :)
   
   ## Summary
   
   Passes `("grpc.so_reuseport", 0)` to ephemeral-port gRPC servers created by 
the Python portability runner (`GrpcServer`, `LocalJobServicer`, 
`SubprocessSdkWorker`, and `UberJarBeamJob`) so distinct servers cannot share a 
port on Linux.
   
   ## Production Impact
   
   This changes production gRPC server setup in the Python portability / 
`FnApiRunner` / local job service stack (`worker_handlers.py`, 
`local_job_service.py`, `abstract_job_service.py`). Previously, on Linux, 
gRPC's default `grpc.so_reuseport=1` allowed multiple independent 
ephemeral-port servers (control, data, state, logging, job service, or artifact 
staging) running under the same user—whether in the same process or across 
concurrent jobs/workers on the same host—to collide on the same port and 
silently misroute RPCs to the wrong servicer with `StatusCode.UNIMPLEMENTED: 
Method not found!`. Explicitly setting `("grpc.so_reuseport", 0)` guarantees 
exclusive port allocation for each server without affecting single-server 
behavior or non-Linux platforms.
   
   ## Root Cause
   
   In `PreCommit Python Runners` (run `45413523150`), 
`PortableRunnerTestWithSubprocesses.test_batch_rebatch_pardos_into_multi_column_batches`
 failed when the subprocess SDK worker's `BeamFnData.Data` stream to 
`localhost:45943` terminated with:
   
   ```
   grpc._channel._MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC 
that terminated with:
     status = StatusCode.UNIMPLEMENTED
     details = "Method not found!"
   >
   ```
   
   Because `grpc.server()` enables `SO_REUSEPORT` by default on Linux, two 
distinct gRPC servers binding ephemeral ports (`[::]:0` / `localhost:0`) under 
the same UID (such as parallel `pytest -n 6` workers or the four separate 
servers inside `GrpcServer`) can receive the same port from the kernel. 
Incoming connections are then hashed across both listeners, routing a 
`BeamFnData` RPC to a server that only implements another service (e.g., 
control, state, logging, or job service).
   
   ## Fix
   
   - Add `("grpc.so_reuseport", 0)` to the gRPC server options in:
     - 
`sdks/python/apache_beam/runners/portability/fn_api_runner/worker_handlers.py` 
(`GrpcServer.__init__`)
     - `sdks/python/apache_beam/runners/portability/local_job_service.py` 
(`LocalJobServicer.start_grpc_server` and `SubprocessSdkWorker.run`)
     - `sdks/python/apache_beam/runners/portability/abstract_job_service.py` 
(`UberJarBeamJob._start_artifact_service`)
   - Add unit tests verifying that a second `grpc.server` cannot bind any port 
owned by `GrpcServer` 
(`WorkerHandlerManagerTest.test_grpc_server_disables_so_reuseport`) or 
`LocalJobServicer` 
(`LocalJobServerTest.test_grpc_server_disables_so_reuseport`).
   
   ## Verification
   
   - Verified formatting with `yapf --style setup.cfg --diff` across all 5 
modified files (clean).
   - Verified locally with `pytest`:
     - `worker_handlers_test.py` + `local_job_service_test.py` (6 passed, 
including both new `SO_REUSEPORT` tests).
     - `flink_uber_jar_job_server_test.py` (6 passed).
     - `portable_runner_test.py -k "PortableRunnerTestWithSubprocesses and 
test_batch_rebatch_pardos_into_multi_column_batches"` (2 passed).
   
   ### Recent Occurrences
   
   1 failing `master` workflow run in the past 3 weeks:
   - `PreCommit Python Runners` (3.14):
     - https://github.com/apache/beam/actions/runs/45413523150 (2026-11-24)
   
   ### Verification
   - Triggered `beam_PreCommit_Python_Runners.yml` workflow run on branch: 
[`45437029119`](https://github.com/apache/beam/actions/runs/45437029119)
   


-- 
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