FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix git clone/fetch hanging indefinitely on unreachable repos by zeevmoney · Pull Request #875 · permitio/opal · GitHub

/ opal Public

Fix git clone/fetch hanging indefinitely on unreachable repos - #875

Draft
zeevmoney wants to merge 1 commit into
masterfrom
zeev/per-13817-fix-git-clonefetch-operations-hanging-indefinitely-on
Draft

Fix git clone/fetch hanging indefinitely on unreachable repos#875
zeevmoney wants to merge 1 commit into
masterfrom
zeev/per-13817-fix-git-clonefetch-operations-hanging-indefinitely-on

Conversation

Copy link
Copy Markdown
Contributor

Summary

  • Add asyncio.wait_for timeout to pygit2 clone_repository and fetch operations in GitPolicyFetcher, preventing indefinite hangs when a git repo is unreachable
  • Wire existing POLICY_REPO_CLONE_TIMEOUT config (previously unused for scoped repos) into GitPolicyFetcher via ScopesService
  • Re-raise pygit2.GitError and asyncio.TimeoutError from _clone() instead of silently swallowing errors, so sync_scope can handle failures properly

Linear Issue

https://linear.app/permit/issue/PER-13817/fix-git-clonefetch-operations-hanging-indefinitely-on

Tests

  • Unit tests added for run_sync_with_timeout (5 tests)
  • Unit tests added for GitPolicyFetcher clone/fetch timeout and error handling (5 tests)
  • Mocks used for all external dependencies (pygit2, git operations)
  • Integration tests: not needed — changes are internal timeout/error handling
  • Test infrastructure: existing pytest + pytest-asyncio

Test plan

  • Verify POLICY_REPO_CLONE_TIMEOUT=0 (default) preserves existing behavior — no timeout applied
  • Verify POLICY_REPO_CLONE_TIMEOUT=30 causes clone/fetch to abort after 30s on unreachable repos
  • Verify error logs include clear timeout/failure messages
  • Verify scopes sharing the same repo lock are unblocked when a clone times out

🤖 Generated with Claude Code

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>

linear Bot commented Feb 5, 2026

Copy link
Copy Markdown

netlify Bot commented Feb 5, 2026
edited
Loading

Copy link
Copy Markdown

Deploy Preview for opal-docs canceled.

Name Link
🔨 Latest commit 1cc1c18
🔍 Latest deploy log https://app.netlify.com/projects/opal-docs/deploys/6984079dc2bfb70008479941

)
try:
repo: Repository = await run_sync(
repo: Repository = await run_sync_with_timeout(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

if the upstream function have "timeout" kwarg then you can't pass it to it, make it more unique

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL