Repository navigation
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 <noreply@anthropic.com>
✅ 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.
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.
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.
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.
if the upstream function have "timeout" kwarg then you can't pass it to it, make it more unique
|
Closing: master already covers this. #924 (git resilience: never stuck on an offline repo) added
#961 and #989 build on the same path. |
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