go build is not working because git getting fatal read error connection reset by peer on Linux

huangapple go评论105阅读模式
英文:

go build is not working because git getting fatal read error connection reset by peer on Linux

问题

我在尝试在Ubuntu上使用go编译内部工具时遇到了一个奇怪的错误。我已经更改了公司敏感信息的名称。

$ go build -o internal-tool .
go: gitlab.com/<company>/platform/<tool-sdk>@v0.0.0-<version-number>: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /home/<myhomefolder>/go/pkg/mod/cache/vcs/<unique-hash>: exit status 128:
    fatal: read error: Connection reset by peer

我已经在每台计算机上添加了用于gitlab的SSH密钥,我可以手动git clone这个tool-sdk,并且克隆正常进行。

如果我在Windows上运行go build -o internal-tool .,情况就很明显了。当它尝试git fetch这个项目时,会显示附加的UI对话框。

我已经设置了双因素身份验证,所以密码无法使用,而且由于某种原因,浏览器从未工作过,它从未加载带有gitlab登录的浏览器窗口。然而,访问令牌确实有效,所以我在Windows上可以这样做。

看起来我的Linux上的go或者我使用的git无法加载此对话框,或者它没有类似的功能以便登录到Gitlab。我的一些同事没有遇到这个问题。另外,如果有用的话,我在Ubuntu上通过apt安装的go和通过snap安装的go(在两台不同的机器上)上都遇到了这个问题。当我在VSCode中打开这个项目时,它也显示了上述错误,所以这并不令人意外。

对于这种情况,有什么建议吗?是否需要针对go进行一些特定的git或gitlab设置?或者需要安装不同的go版本?

英文:

I am getting a weird error on Ubuntu attempting to compile an internal tool at work, with go. I've changed names for company sensitivity

$ go build -o internal-tool .
go: gitlab.com/&lt;company&gt;/platform/&lt;tool-sdk&gt;@v0.0.0-&lt;version-number&gt;: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /home/&lt;myhomefolder&gt;/go/pkg/mod/cache/vcs/&lt;unique-hash&gt;: exit status 128:
	fatal: read error: Connection reset by peer

I have my SSH keys to gitlab added for every computer I have tried this on, I am able to git clone this tool-sdk manually, and it clones just fine.

If I ran go build -o internal-tool . on Windows, it's very telling. When it tries to git fetch this project it displays the attached UI dialog box

go build is not working because git getting fatal read error connection reset by peer on Linux

I have 2FA setup so password doesn't work, and for some reason, Browser never worked, it never loaded the browser window with the gitlab login. Access token did work however, so I was able to do this on Windows.

It looks like my go or the git that my go is using on Linux, does not have the ability to load this dialog box or it does not have an analog for this in order to login to Gitlab. I have coworkers who have not run into this issue. Also if it's any use, I have seen this both on the go installed via apt on Ubuntu and on the go install using snap on Ubuntu (on two different machines). When I open this project in VSCode, it also relays the above error, so no surprise there.

Any suggestions on what to do here? Is there some git or gitlab setup that I have to do specific to go? Or a different go needs to be installed?

答案1

得分: 2

提示要求输入密码或令牌意味着您的项目的某个依赖项需要使用HTTPS URL(而不是SSH URL)来克隆它。

对话框本身来自GCM(Git凭据管理器),它在其v2.0.692中添加了对GitLab存储库的支持,并为GitLab身份验证添加了GUI提示。

您可以通过在执行go build的shell中使用export GCM_INTERACTIVE=false来确保不会看到任何弹出窗口,这样可以确保构建失败时会显示错误消息而不是弹出窗口。

在您的情况下,请尝试执行以下命令:

git config --global url.ssh://git@gitlab.com/.insteadOf https://gitlab.com/

这将尝试使用SSH URL。

英文:

A prompt asking for a password or token means one of the dependencies of your project requires Go to clone it using an HTTPS URL (not an SSH one)

The dialog box itself comes from the GCM (Git Credential Manager) which includes in its v2.0.692 with the support for GitLab repositories, adding GUI prompts for GitLab authentication.

Not that you can make sure you don't see any popup with export GCM_INTERACTIVE=false in the shell where you do a go build, ensuring the build fails with an error message instead of a popup.

In your case, try:

git config --global url.ssh://git@gitlab.com/.insteadOf https://gitlab.com/

That will try and use SSH URL instead.

答案2

得分: 0

在我的情况下,GOPATH存在问题。请检查您的路径变量是否包括&lt;GOPATH&gt;/bin,只需输入echo $PATH即可。

您可以将其临时添加到您的shell中:

export PATH=$PATH:$(go env GOPATH)/bin

要永久添加到您的shell中,请编辑~/.zshr~/.bashrc文件,然后重新加载shell:

$SHELL

有关更多关于GOPATH的信息,请参阅链接。

英文:

In my case, GOPATH has an issue. Check that your path variable also includes the &lt;GOPATH&gt;/bin just type echo $PATH.

You can add it to your shell temporary

export PATH=$PATH:$(go env GOPATH)/bin

to add it to your shell permanently edit ~/.zshr or ~/.bashrc then source the shell

$SHELL

More info about the GOPATH

huangapple
  • 本文由 发表于 2022年5月3日 06:54:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/72093194.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定