Repository navigation
Serialize the frpc download so parallel harbor rollouts can share a fresh machine - #1568
Open
sergiopaniego wants to merge 1 commit into
Open
sergiopaniego wants to merge 1 commit into
sergiopaniego wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Starting several
openenv harbor rollout --expose gradioprocesses at once on a fresh machine made some of them fail their first task withText file busy, because each one's first tunnel downloads gradio's frpc binary to the same path. The download now happens under a file lock, so one process downloads and the others wait.Type of Change
What was wrong
Running 3 to 12 rollout processes in parallel on one HF Job, each on its own
--port, some failed their first task before the agent ran, withText file busy. Starting the workers 20 s apart avoided it, and once the binary was on disk every later tunnel worked.Root cause
GradioForwarder.start(src/openenv/core/harness/capture/forwarding.py) calls gradio'ssetup_tunnel, which callsTunnel.download_binary(gradio/tunneling.py:83-110, gradio 6.31.0). It checks whetherBINARY_PATHexists and then writes the binary in place at$HF_HOME/gradio/frpc/frpc_<os>_<arch>_v0.3. While the first process is still writing, a second sees the file, skips the download and executes it: the kernel refuses to exec a file open for writing (ETXTBSY), or the process runs a truncated binary.Fix
GradioForwarder._ensure_frpc_binarytakes an exclusivefcntl.flockon<binary>.locknext to the binary and calls gradio's ownTunnel.download_binaryinside it. The first process downloads, the others wait and then find a complete file.setup_tunnelruns as before and finds the binary in place. Download errors still raiseForwardingError, the lock costs nothing once the binary exists, and Windows (nofcntl) keeps gradio's behaviour. No gradio internals are patched and no dependency is added.RFC Status
Test Plan
tests/envs/test_harbor_frpc_download_race.py: two threads call_ensure_frpc_binaryagainst a fake downloader shaped like gradio's (check, then write in place, pausing halfway). Without the lock the second caller reads the half-written file and the test fails. With it, the second caller reads the full file and only one download happens.tests/envs/test_harbor_forwarding_lifecycle.py: the fakegradio.tunnelingmodule also providesBINARY_PATHandTunnel.Across
tests/envs/test_harbor_*.pythe only failure (test_harbor_capture_server.py::test_start_refuses_a_port_held_by_a_non_capture_listener) also fails on main.ruff format,ruff checkandusortare clean.Claude Code Review
N/A
Note
Low Risk
Targets gradio tunnel startup with an advisory file lock and unchanged Windows path; adds regression coverage with limited blast radius beyond first tunnel setup.
Overview
Parallel harbor rollouts no longer race on a half-written
frpcbinary.GradioForwarder.startnow calls_ensure_frpc_binary, which opens a.lockfile beside gradio’s binary path, takes an exclusivefcntl.flockwhen available, then invokes gradio’sTunnel.download_binary. The first process downloads; others wait until the lock releases, then reuse the complete file.fcntlis optional (Windows import failure leavesfcntlunset so locking is skipped and behavior matches gradio’s today).Tests stub
BINARY_PATHandTunnel.download_binaryin the existing lifecycle test sostartstill works. A newtest_harbor_frpc_download_raceruns two threads against a fake downloader that pauses mid-write and asserts the second thread only sees a fully written binary and that only one download runs.Reviewed by Cursor Bugbot for commit ddf2971. Bugbot is set up for automated code reviews on this repo. Configure here.