Error when cloning a repository using SSH: LibGit2Sharp.LibGit2SharpException: failed to connect to "GitHub URL": Invalid argument

LibGit2Sharp.LibGit2SharpException: failed to connect to "GitHub URL": Invalid argument


Issue Description

When trying to Clone a Git repository using SSH, the below error may occur:

GIT: UiPath.Studio.Contracts.RecoverableException: Unable to clone from the given repository. Please make sure that the remote is available and try again.

---> LibGit2Sharp.LibGit2SharpException: failed to connect to github.com: Invalid argument

at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in C:\work\uipathgit\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 156

at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts) in C:\work\uipathgit\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 278

at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options) in C:\work\uipathgit\libgit2sharp\LibGit2Sharp\Repository.cs:line 793

at UiPath.Studio.Plugin.Git.Desktop.Services.UiAuthenticationSession.Execute[T](ExecuteArgs`1 args)

at UiPath.Studio.Plugin.Git.Services.CloneService.CheckoutCore(String uri, String localFolder, IAuthenticationSession authenticationSession)

--- End of inner exception stack trace ---

at UiPath.Studio.Plugin.Git.Services.CloneService.CheckoutCore(String uri, String localFolder, IAuthenticationSession authenticationSession)

at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)

--- End of stack trace from previous location ---

at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)

--- End of stack trace from previous location ---

at UiPath.Studio.Plugin.Git.Services.CloneService.Checkout(String repository, String localFolder, IAuthenticationSession authenticationSession)

at UiPath.Studio.Plugin.Git.Desktop.Services.CheckOutUiService.CheckOut_ExecuteInternal()

at UiPath.Studio.SourceControl.Shared.Desktop.Services.BaseCheckOutUiService`1.CheckOut_Execute()

at UiPath.Studio.SourceControl.Shared.Desktop.Services.BaseCheckOutUiService`1.b__11_0()

at UiPath.Studio.App.Desktop.MVVM.Commands.TaskCommand`3.Execute(TExecuteParameter parameter, Boolean ignoreCanExecuteCheck)

at System.Threading.Tasks.Task.<>c.b__128_0(Object state)

at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)

at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler), HResult -2146233088

General information

Access to a Git repository via SSH, a secure protocol, is provided through SSH URLs. For these URLs to be usable, an SSH keypair needs to be generated on the respective computer and the public key should be added to the account on GitHub. For more information, see "Connecting to GitHub with SSH."

Root Cause

  1. Network issues mostly cause this error it could be due to internal firewall rules.
  2. Make sure port 22 is open otherwise the error above will be thrown.

General troubleshooting

  1. Make sure to check with the internal Network/IT team if a successful connection can be made by using the the port 22.
  2. Attempting a connection with Git bash is advisable if the initial connection is unsuccessful. Additionally, it could be beneficial to verify with the IT team about any potential internal network restrictions.

  • A warning like this may be seen:

  • Verification is needed to ensure that the fingerprint in the displayed message matches the enterprise's public key fingerprint. If it aligns, typing 'yes' should be done (the screenshot below demonstrates a successful test connection):

  • In the below example the port 22 was blocked which caused that error and also the above error in Studio when cloning a repository:

3. If the issue continues, conducting a Wireshark capture should help identify whether the connection is successful or confirm if the problem is network-related (the example below illustrates a proper connection).

4. If possible, review the ability to clone the repository from a different network or machine, given that such action aligns with the respective security policy.

If a solution is still not found, sharing the information described below, collected from the machine experiencing the issue, would be beneficial:

  1. Capture Diagnostic logs from the machine where this issue occurs.
  2. (If possible) Wireshark captures.
  3. Share the timestamp of when the issue was reproduced.