Skip to content
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

Use standard git instead of LibGit2Sharp #509

Open
Ricardo-Evans opened this issue Dec 27, 2024 · 5 comments
Open

Use standard git instead of LibGit2Sharp #509

Ricardo-Evans opened this issue Dec 27, 2024 · 5 comments

Comments

@Ricardo-Evans
Copy link

Recently I meet the following errors frequently:

LibGit2Sharp.LibGit2SharpException: could not initialize security context: too many retries
at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in //LibGit2Sharp/Core/Ensure.cs:line 154
at LibGit2Sharp.Core.Proxy.git_remote_fetch(RemoteHandle remote, IEnumerable1 refSpecs, GitFetchOptions fetchOptions, String logMessage) in /_/LibGit2Sharp/Core/Proxy.cs:line 2289 at LibGit2Sharp.Commands.Fetch(Repository repository, String remote, IEnumerable1 refspecs, FetchOptions options, String logMessage) in /
/LibGit2Sharp/Commands/Fetch.cs:line 79
at LibGit2Sharp.Commands.Pull(Repository repository, Signature merger, PullOptions options) in /_/LibGit2Sharp/Commands/Pull.cs:line 31
at Noggog.GitRepository.GitRepository.Pull()
at Noggog.GitRepository.ResetToLatestMain.TryReset(IGitRepository repo)
at Synthesis.Bethesda.Execution.Patchers.Git.Services.PrepareDriver.PrepareDriverRespository.Prepare(GetResponse`1 remotePath, CancellationToken cancel) in D:\a\Synthesis\Synthesis\Synthesis.Bethesda.Execution\Patchers\Git\Services\PrepareDriver\PrepareDriverRespository.cs:line 66

Restart Synthesis usually helps but sometimes also fail too. I'm a developer myself so I use git frequently in my daily life, and never meet similar problems. I guess it can be some differences between standard git and LibGit2Sharp

@Noggog
Copy link
Member

Noggog commented Dec 27, 2024

I haven't seen anyone report this specific error message before. Does it always fail for you? Or is it a random unpredictable error that only happens occasionally?

The main reason I haven't leaned on normal git is that that would be another installation step for users, which are already often overwhelmed by the SDK installation requirements. Libgit2sharp was a way to do git work without requiring users install another thing

@Ricardo-Evans
Copy link
Author

Actually I have already figured out the root cause. I have multiple network interfaces on my computer, one for the normal internet and others are used for lan, such as wireguards etc. By inspecting the packet capture results generated by wireshark, Libgit2sharp try to broadcast the requests on all interfaces without follow the routing table, and as you can imagine, those lan interfaces will reject the request. So the behavior in theory depends on which interface reacts first. If the internet interface reacts first, it will be fine, otherwise Libgit2sharp will retry on the lan interfaces and quickly reach the retry limit.
The theory match with my experience. When I have only one Synthesis patcher, it has about 50% success rate. But when I have multiple patchers, the fail rate increases very fast, as any patcher fail will block the whole processure. Currently I found a temparature solution by disabling all the lan interfaces before launching synthesis, and the success rate is 100% now.

@Ricardo-Evans
Copy link
Author

I also tried other solutions, like configuring a proxy to git so Libgit2sharp can follow it as proposed in Libgit2sharp#PR 2065. But then I meet another behavior where Libgit2sharp doesn't follow the standard git, as it didn't support socks5 proxies, which already have a long history in standard git. Here is the error message:

[17.5][Skyrim Special Edition][Mutagen Git Patcher] Error downloading patcher listing
LibGit2Sharp.LibGit2SharpException: unknown http scheme 'socks5'
at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in //LibGit2Sharp/Core/Ensure.cs:line 154
at LibGit2Sharp.Core.Proxy.git_remote_fetch(RemoteHandle remote, IEnumerable1 refSpecs, GitFetchOptions fetchOptions, String logMessage) in /_/LibGit2Sharp/Core/Proxy.cs:line 2289 at LibGit2Sharp.Commands.Fetch(Repository repository, String remote, IEnumerable1 refspecs, FetchOptions options, String logMessage) in /
/LibGit2Sharp/Commands/Fetch.cs:line 79
at LibGit2Sharp.Commands.Pull(Repository repository, Signature merger, PullOptions options) in /_/LibGit2Sharp/Commands/Pull.cs:line 31
at Noggog.GitRepository.GitRepository.Pull()
at Noggog.GitRepository.ResetToLatestMain.TryReset(IGitRepository repo)
at Synthesis.Bethesda.Execution.Patchers.Git.Services.Registry.PrepRegistryRepository.Prep(CancellationToken cancellationToken) in D:\a\Synthesis\Synthesis\Synthesis.Bethesda.Execution\Patchers\Git\Services\Registry\PrepRegistryRepository.cs:line 49
at Synthesis.Bethesda.Execution.Patchers.Git.Services.Registry.RegistryListingsProvider.Get(CancellationToken cancel) in D:\a\Synthesis\Synthesis\Synthesis.Bethesda.Execution\Patchers\Git\Services\Registry\RegistryListingsProvider.cs:line 33
at Synthesis.Bethesda.Execution.Patchers.Git.Services.Registry.ApplicablePatcherListingsProvider.Get(CancellationToken cancel) in D:\a\Synthesis\Synthesis\Synthesis.Bethesda.Execution\Patchers\Git\Services\Registry\ApplicablePatcherListingsProvider.cs:line 25
at Synthesis.Bethesda.GUI.ViewModels.Patchers.Initialization.Git.GitPatcherInitVm.<>c__DisplayClass46_0.<<-ctor>b__4>d.MoveNext() in D:\a\Synthesis\Synthesis\Synthesis.Bethesda.GUI\ViewModels\Patchers\Initialization\Git\GitPatcherInitVm.cs:line 108

@Ricardo-Evans
Copy link
Author

As for how to use standard git without introduing another installation step, including a copy of git may be a solution? I'm not sure on these things since git is already a must have tool for me.

I also have another idea. I think the current working procedure of synthesis is a little weird, as it clones all the patchers everytime it lanches. Maybe a persistent local repo can help a lot, so users only need to update the patchers if necessary, and synthesis can be used offline. I'm willing to offer help if you think its a reasonable idea.

@Noggog
Copy link
Member

Noggog commented Dec 29, 2024

Interesting! Thanks for the outline of your issues

including a copy of git may be a solution?

Yeah, Libgit2sharp is definitely an odd library. Potentially something to consider. Another idea is to expose the flexibility of using libgit2sharp OR leaning on git commands. That way, a user like yourself could opt to use installed git and bypass libgit2sharp. Or, maybe an auto option, where it tries a git command, and if it's found to exist, uses git commands... otherwise falls back to libgit2sharp.

On that note, most of the git calls flow through this library interface, so would/could just upgrade that library to have alternatives that called git commands instead of libgit2sharp. From there, would be an easy DI swapout to one implementation or the other

it clones all the patchers everytime it lanches

It shouldn't be. It clones each patcher into %temp%/Synthesis/[profile ID]/... and reuses the clones there. In fact, it even goes farther and has a dotnet build caching system, where it save the last commit it compiled, so that on next startup it can skip running dotnet build on all the projects if it knows they're prepped.

What did you see that suggested it was cloning every time? Maybe something is up

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

No branches or pull requests

2 participants