git2-rs
git2-rs copied to clipboard
SSL errors
I'm using git2 to periodically check changes in a repository. Sometimes I start getting SSL error: received early EOF; class=Ssl (16); code=Eof (-20) errors while pulling from the repository (github). When such errors start to happen they usually don't stop happening until I restart the service. (And when I restart the service the erros are gone for days)
Is there anything I can do to prevent / help debug this issue?
The pull function looks something like this:
fn pull(repo: &Repository, ch: Sender<Info>) -> Result<(), git2::Error> {
// fetch changes from remote index
repo.find_remote("origin")?.fetch(&["master"], None, None)?;
// Collect all commits in the range `HEAD~1..FETCH_HEAD` (i.e. one before
// currently checked out to the last fetched)
let mut walk = repo.revwalk()?;
walk.push_range("HEAD~1..FETCH_HEAD")?;
walk.set_sorting(Sort::TOPOLOGICAL | Sort::REVERSE)?;
let commits: Result<Vec<_>, _> = walk.map(|oid| repo.find_commit(oid?)).collect();
let mut opts = DiffOptions::default();
let opts = opts.context_lines(0).minimal(true);
for [prev, next] in Slice::array_windows::<[_; 2]>(&commits?[..]) {
let diff = repo.diff_tree_to_tree(Some(&prev.tree()?), Some(&next.tree()?), Some(opts))?;
// Send info
ch.blocking_send(Info::from(diff)).ok().unwrap();
// 'Move' to the next commit
fast_forward(repo, next)?;
}
Ok(())
}
/// Fast-Forward (FF) to a given commit.
///
/// Implementation is taken from <https://stackoverflow.com/a/58778350>.
fn fast_forward(repo: &Repository, commit: &git2::Commit) -> Result<(), git2::Error> {
let fetch_commit = repo.find_annotated_commit(commit.id())?;
let analysis = repo.merge_analysis(&[&fetch_commit])?;
if analysis.0.is_up_to_date() {
Ok(())
} else if analysis.0.is_fast_forward() {
let mut reference = repo.find_reference("refs/heads/master")?;
reference.set_target(fetch_commit.id(), "Fast-Forward")?;
repo.set_head(reference.name().unwrap())?;
repo.checkout_head(Some(git2::build::CheckoutBuilder::default().force()))
} else {
Err(git2::Error::from_str("Fast-forward only!"))
}
}
Seems to be a longstanding issue with the upstream :(
https://github.com/libgit2/libgit2/issues/5279