Sudden ~10 min Delay in `RepoBuilder::clone` Without `Code/Dependency` Changes
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 25/100
- issue の種類
- バグ
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- git, rust
- 領域
- networking, tooling
調査の方向性
リポジトリのソースファイルやテストは指定されていません。提供されている RepoBuilder::clone と clone_with_git2 の再現コードから始め、fetch、checkout、認証のコールバックを観察しながら、git2-rs の所要時間とコマンドライン git の所要時間を比較してください。遅延の再現可能な原因を特定するか、環境、サーバーの応答、または非同期使用に依存することを文書化できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Sudden Performance Degradation in Async RepoBuilder::clone (approx. 10 min delay)
Problem Description:
I am experiencing a significant and sudden performance degradation when cloning repositories using git2-rs. An operation that previously completed quickly now takes approximately 10 minutes. This slowdown started occurring recently without any intentional changes to my code or explicit dependency updates (Cargo.lock appears unchanged relative to when it was working fast).
Cloning the same repository using command-line git or downloading related resources via curl with the same token remains fast, suggesting the issue is specific to the git2-rs interaction or its underlying libgit2 usage in my setup, potentially related to the async context or authentication.
Environment:
git2-rsversion: [0.20.1]libgit2-sysversion: [0.18.1+1.9.0]- Rust Version: rustc 1.86.0**]
- Operating System: [e.g., Linux Ubuntu 22.04]
Code Snippet:
Here is the relevant function performing the clone:
fn test_git2(repo_url: &str, dest_path: &Path, token: Option<String>) {
println!("\n=== Testing git2 library (with detailed progress) ===");
// Optional: Clean up destination directory before cloning if it exists
// This prevents errors if the directory exists and is not empty,
// especially since CheckoutBuilder.force() might be needed.
if dest_path.exists() {
println!("Removing existing directory: {}", dest_path.display());
if let Err(e) = std::fs::remove_dir_all(dest_path) {
println!("Warning: Failed to remove existing directory {}: {}", dest_path.display(), e);
// Decide if you want to proceed or return an error here
}
}
let start = Instant::now();
let result = clone_with_git2(repo_url, dest_path, token);
let elapsed = start.elapsed();
match result {
Ok(_) => println!("\ngit2 clone successful in {:.4} seconds", elapsed.as_secs_f64()), // Added newline for cleaner output
Err(e) => println!("\ngit2 clone failed: {:?}", e), // Added newline
}
}
fn clone_with_git2(repo_url: &str, dest_path: &Path, token: Option<String>) -> Result<Repository, git2::Error> {
// --- 1. Setup Fetch Options ---
let mut fetch_options = FetchOptions::new();
fetch_options.update_fetchhead(false); // Don't update FETCH_HEAD (minor optimization)
fetch_options.depth(1); // Shallow clone - only get the latest commit
// --- 2. Setup Remote Callbacks (Authentication & Fetch Progress) ---
let mut callbacks = RemoteCallbacks::new();
// Detailed Transfer (Fetch) Progress Reporting
callbacks.transfer_progress(|progress: Progress| {
let network_pct = if progress.total_objects() > 0 {
(100 * progress.received_objects()) / progress.total_objects()
} else { 0 };
let index_pct = if progress.total_objects() > 0 {
(100 * progress.indexed_objects()) / progress.total_objects()
} else { 0 };
let kbytes = progress.received_bytes() / 1024;
// Print progress information without a newline, using '\r' to overwrite the line
print!(
"Fetch Progress: net {:3}% ({:4} kb, {:>5}/{:<5}) / idx {:3}% ({:>5}/{:<5})\r",
network_pct,
kbytes,
progress.received_objects(),
progress.total_objects(),
index_pct,
progress.indexed_objects(),
progress.total_objects()
);
// Flush stdout to ensure the progress is displayed immediately
io::stdout().flush().unwrap();
true // Return true to continue the transfer
});
// Authentication Callback (if token is provided)
if let Some(token_str) = token {
// Clone the token string so it can be moved into the closure
let token_clone = token_str.clone();
callbacks.credentials(move |_, _, _| {
// This closure will be called by libgit2 when authentication is needed
// println!("Credentials callback invoked"); // Uncomment for debugging auth calls
Cred::userpass_plaintext("oauth2", &token_clone)
});
}
// Apply the callbacks to the fetch options
fetch_options.remote_callbacks(callbacks);
// --- 3. Setup Checkout Builder (Checkout Progress) ---
let mut checkout_builder = CheckoutBuilder::new();
checkout_builder.force(); // Force checkout to overwrite files if they exist
// Equivalent to `git clone --force` behavior.
// Remove if you want it to fail if the directory has conflicting files.
// Detailed Checkout Progress Reporting
checkout_builder.progress(|path, current, total| {
let path_str = path.map(|p| p.to_string_lossy()).unwrap_or_default();
// Print progress, overwriting the line with '\r'
print!("Checkout Progress: [{}/{}] {}\r", current, total, path_str);
// Flush stdout to ensure the progress is displayed immediately
io::stdout().flush().unwrap();
});
// --- 4. Setup Repo Builder (combines fetch and checkout) ---
let mut repo_builder = RepoBuilder::new();
repo_builder.bare(false); // Ensure it's not a bare repo (we want a working directory)
repo_builder.fetch_options(fetch_options); // Use the fetch options configured above
repo_builder.with_checkout(checkout_builder); // Use the checkout builder configured above
println!("Starting git2 clone (shallow, depth=1) from {} to {}", repo_url, dest_path.display());
// --- 5. Perform the Clone ---
// This call will use the configured fetch_options (including callbacks)
// and the configured checkout_builder (including its progress callback).
let result = repo_builder.clone(repo_url, dest_path);
// Print a newline character after the progress indicators are done to avoid messing up subsequent output
println!();
result // Return the result of the clone operation
}
Could there be any known issues, potential deadlocks, or changes in recent libgit2 or git2-rs versions that might cause such a delay, especially when interacting with authentication callbacks or specific server responses within an async context (even if correctly using spawn_blocking)? Are there recommended steps for diagnosing network or callback-related hangs within libgit2 from git2-rs (e.g., enabling libgit2 tracing)?
Adding detailed progress callbacks (for fetch and checkout, as shown in other examples) might provide more granular clues, but I wanted to report the sudden change and the potential async interaction issue first.
Thank you for your time and insights!
- 主要言語
- Rust
- スター
- 2.1k
- フォーク
- 470
- 平均マージ
- 2日 17時間
- マージ済み PR(30日)
- 18
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rust-lang/git2-rs のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
`stash_foreach` crashes on stash entries with no message or a non-UTF-8 message対応中かも @shivampwm2020 が 43 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信
rust-lang/git2-rs の issue をすべて見る
似ている issue
-
bug P2
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
Windows microphone listing treats words in a device name as DirectShow labels対応中かも @Sujal-chaudhary が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
clipy-recorder/clipy#447 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
nightly-cleanup
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
max-sixty/worktrunk#4939 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Flaky Test] tests::signer::v0::miner_recovers_when_broadcast_block_delay_across_tenures_occursオープンflaky
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
stacks-network/stacks-core#7918 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信