-
Notifications
You must be signed in to change notification settings - Fork 268
Fix git clone/fetch hanging indefinitely on unreachable repos #875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix git clone/fetch hanging indefinitely on unreachable repos #875
Conversation
Add timeout support to server-side pygit2 clone and fetch operations via asyncio.wait_for. Wire existing POLICY_REPO_CLONE_TIMEOUT config into GitPolicyFetcher. Re-raise errors from _clone() instead of silently swallowing them so callers can handle failures properly. Co-Authored-By: Claude Opus 4.5 <[email protected]>
✅ Deploy Preview for opal-docs canceled.
|
| ) | ||
| try: | ||
| repo: Repository = await run_sync( | ||
| repo: Repository = await run_sync_with_timeout( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to make sure that in case of a timeout, we actually terminate the Git subprocess
| datetime.datetime.now() | ||
| ) | ||
| try: | ||
| await run_sync_with_timeout( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Timeout should be for the entire sync procedure, not individually fetch and clone. That would naturally double the actual timeout
| return False | ||
| return last_fetched > t | ||
|
|
||
| async def fetch_and_notify_on_changes( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should instrument this function
| async def run_sync_with_timeout( | ||
| func: Callable[P_args, T_result], | ||
| *args: P_args.args, | ||
| timeout: Optional[float] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the upstream function have "timeout" kwarg then you can't pass it to it, make it more unique
Summary
asyncio.wait_fortimeout to pygit2clone_repositoryandfetchoperations inGitPolicyFetcher, preventing indefinite hangs when a git repo is unreachablePOLICY_REPO_CLONE_TIMEOUTconfig (previously unused for scoped repos) intoGitPolicyFetcherviaScopesServicepygit2.GitErrorandasyncio.TimeoutErrorfrom_clone()instead of silently swallowing errors, sosync_scopecan handle failures properlyLinear Issue
https://linear.app/permit/issue/PER-13817/fix-git-clonefetch-operations-hanging-indefinitely-on
Tests
run_sync_with_timeout(5 tests)GitPolicyFetcherclone/fetch timeout and error handling (5 tests)Test plan
POLICY_REPO_CLONE_TIMEOUT=0(default) preserves existing behavior — no timeout appliedPOLICY_REPO_CLONE_TIMEOUT=30causes clone/fetch to abort after 30s on unreachable repos🤖 Generated with Claude Code