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

Cargo build failed with spurious network error #6513

Open
weiby3 opened this issue Jan 2, 2019 · 104 comments
Open

Cargo build failed with spurious network error #6513

weiby3 opened this issue Jan 2, 2019 · 104 comments
Labels
A-networking Area: networking issues, curl, etc. C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@weiby3
Copy link

weiby3 commented Jan 2, 2019

Problem
error: failed to load source for a dependency on rand

Steps

$ cargo run --verbose
    Updating registry `https://github.com/rust-lang/crates.io-index`
warning: spurious network error (2 tries remaining): failed to send request: 无法与服务器建立连接
; class=Os (2)
warning: spurious network error (1 tries remaining): failed to send request: 无法与服务器建立连接
; class=Os (2)
error: failed to load source for a dependency on `rand`

Caused by:
  Unable to update registry `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to send request: 无法与服务器建立连接
; class=Os (2)

The chinese sentences above are "Unable to establish connection to server".
I have check my firewall, cargo isn't blocked, and there is personal CA installed by Adguard, no proxy.

Notes
OS: Windows 7 64bit, mingw64 with MSYS2
Output of cargo version: cargo 1.29.0

@weiby3 weiby3 added the C-bug Category: bug label Jan 2, 2019
@alexcrichton
Copy link
Member

Hm is this perhaps a network-level issue where github.com or github.com/rust-lang is blocked? Otherwise I'm not sure how we'd fix this as it seems Cargo can't connect :(

@weiby3
Copy link
Author

weiby3 commented Jan 2, 2019

I try git clone and curl https://github.com/rust-lang and they works fine.
On my computer github.com can be accessed successfully, I have search the firewall and there aren't any block rule related to it.
Maybe these are some useful information.
I use HUORONG SECURITY as my anti-virus software, and if there is a program trying to connect to Internet, it will popup a windows and ask for permission.
Strangely when I run cargo run --verbose there is no popup window, but if I run curl https://github.com/rust-lang there is a popup window, so it seems Cargo can't connect.
Is it possible to get more error information?

@alexcrichton
Copy link
Member

Hm so AFAIK there's a few different ways to touch the network on Windows, and it may be that Cargo, through libgit2, is using a different way that's may blocked or doesn't provide a popup? Can you temporarily disable your firewall/virus scanning to see if that fixes the issue?

@ddw360
Copy link

ddw360 commented Jan 3, 2019

@alexcrichton Disabling antivirus, firewalls, etc - don't seem to work. I was able to do a cargo build in Windows 10 x64 but not in Windows Subsystem for Linux. Both have versions re: nightly, etc. The build fails when trying to retrieve from github dependencies. Command issued was "cargo build --release --target=wasm32-unknown-unknown"

@alexcrichton
Copy link
Member

Hm interesting! So this probably isn't a firewall/antivirus issue if you've disabled all those and it still didn't work. It works on Windows though and not the WSL? What we use on Linux is far more bog-standard I think than the Windows implementation, so I'm surprised it wouldn't work there if it works on Windows... I wonder if that's a WSL bug?

@ddw360
Copy link

ddw360 commented Jan 3, 2019

WSL environment info:
Linux ZEPHYR 4.4.0-17134-Microsoft #471-Microsoft Fri Dec 07 20:04:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux
PRETTY_NAME="Ubuntu 16.04.5 LTS"
Architecture: x86_64

Don't know if it matters or not - but here are contents of Cargo.toml below and the git repos that the cargo build command is trying to pull for dependencies. when "cargo build --release --target=wasm32-unknown-unknown" is issued. Fails on trying to resolve the first "hdk" dependency.

[package]
name = "chat"
version = "0.1.0"
authors = ["willem willemolding@gmail.com"]
edition = "2018"
[dependencies]
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
machine-ip = "0.2.1"
hdk = { git = "https://github.com/holochain/holochain-rust" , branch = "master" }
holochain_wasm_utils = { git = "https://github.com/holochain/holochain-rust" , branch = "master" }
holochain_core_types_derive = { git = "https://github.com/holochain/holochain-rust" , branch = "master" }
[lib]
path = "src/lib.rs"
crate-type = ["cdylib"]

@alexcrichton
Copy link
Member

Can you perhaps try strace? That may help illuminate which syscall is failing and may help tracking this down?

@ddw360
Copy link

ddw360 commented Jan 3, 2019

@weiby3
Copy link
Author

weiby3 commented Jan 4, 2019

Sorry for late response.
I have tried to disable firewall and anti-virus software, but it still has this problem.
Is it possible to expose the download directory filename and/or commands? Maybe try to do it by myself can solve this problem.

@ddw360
Copy link

ddw360 commented Jan 4, 2019

@weiby3 @alexcrichton Weiby3 - I am curious if you are in actual Windows standard command line, powershell or a WSL environment when encountering issues. I haven't tested doing things in Powershell but do get the spurious network error in WSL.

@weiby3
Copy link
Author

weiby3 commented Jan 4, 2019

I have tried in cmd.exe and got the same problem. Windows 7 doesn't have WSL, so I can't try. Powershell also not work.

@alexcrichton
Copy link
Member

@ddw360 do you perhaps have a proxy configured? It looks like an ntlm proxy or something like that, running on port 3128

@ddw360
Copy link

ddw360 commented Jan 4, 2019

@alexcrichton don't think so - here is my evidence:

  1. from Windows cmd prompt: netstat -abno | findstr /R "^.:3128.$" --> no results

  2. Internet Explorer Settings - no proxy being used for internet connection

  3. whatismyipaddress:
    Hostname: | cpe-76-170-98-202.socal.res.rr.com
    Services: None detected
    Proxy server not detected.
    Broadband
    Dynamic IP

  4. netstat from bash (ubuntu 16.04) shows no use of proxy port 3128

  5. /etc/resolv.conf shows no use of proxy - nameservers are all gateway addresses and then gateway pointed to publ
    ic dns/internet

  6. git version is 2.7.4 (<< i am going to try to get a later version of git by compiling from source and see if that does the trick since cargo relies on git - since current ubuntu is 16.04).

I am going to try to move to WSL ubuntu 18.04 LTS and a higher git version and see if that changes things at all.

@weiby3
Copy link
Author

weiby3 commented Jan 4, 2019

If I try to run cargo via a proxy, it can "Updating registry https://github.com/rust-lang/crates.io-index", but it will get the following output:

$ https_proxy=socks5://127.0.0.1:1080 cargo run --verbose
 Downloading winapi-x86_64-pc-windows-gnu v0.4.0
error: unable to get packages from source

Caused by:
  [35] SSL connect error (schannel: failed to receive handshake, SSL/TLS connection failed)

Othrtwise, I try to install rust with msvc, it can download and build successfully.

c:\msys64\tmp\rust\guessing_game>cargo run
   Compiling winapi v0.3.6
   Compiling libc v0.2.46
   Compiling rand v0.4.3
   Compiling rand v0.3.22
   Compiling guessing_game v0.1.0 (C:\msys64\tmp\rust\guessing_game)
    Finished dev [unoptimized + debuginfo] target(s) in 7.72s
     Running `target\debug\guessing_game.exe`
Guess the number!
Please input your guess.
123
You guessed: 123

UPDATE:
After download rust package via proxy, I run cargo without proxy, and it build successfully.
Here are all the commands I have tried and their output:

$ cargo run --verbose
    Updating registry `https://github.com/rust-lang/crates.io-index`
warning: spurious network error (2 tries remaining): failed to send request: 无法与服务器建立连接
; class=Os (2)
warning: spurious network error (1 tries remaining): failed to send request: 无法与服务器建立连接
; class=Os (2)
error: failed to load source for a dependency on `rand`

Caused by:
  Unable to update registry `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to send request: 无法与服务器建立连接
; class=Os (2)
$ https_proxy=socks5://127.0.0.1:1080 cargo run --verbose
    Updating registry `https://github.com/rust-lang/crates.io-index`
 Downloading rand v0.3.22
error: unable to get packages from source

Caused by:
  [35] SSL connect error (schannel: failed to receive handshake, SSL/TLS connection failed)
https_proxy=socks5://127.0.0.1:1080 cargo run --verbose
 Downloading rand v0.3.22
error: unable to get packages from source

Caused by:
  [35] SSL connect error (schannel: failed to receive handshake, SSL/TLS connection failed)
$ cargo run --verbose
   Compiling winapi-x86_64-pc-windows-gnu v0.4.0
   Compiling winapi v0.3.6
   Compiling libc v0.2.46
     Running `rustc --crate-name build_script_build 'C:\Users\Administrator\.cargo\registry\src\github.com-1ecc6299db9ec823\winapi-x86_64-pc-windows-gnu-0.4.0\build.rs' --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=cd7a6ff3618fa678 -C extra-filename=-cd7a6ff3618fa678 --out-dir 'C:\msys64\tmp\rust\guessing_game\target\debug\build\winapi-x86_64-pc-windows-gnu-cd7a6ff3618fa678' -L 'dependency=C:\msys64\tmp\rust\guessing_game\target\debug\deps' --cap-lints allow`
     Running `rustc --crate-name build_script_build 'C:\Users\Administrator\.cargo\registry\src\github.com-1ecc6299db9ec823\winapi-0.3.6\build.rs' --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg 'feature="minwindef"' --cfg 'feature="ntsecapi"' --cfg 'feature="profileapi"' --cfg 'feature="winnt"' -C metadata=db0e30f3a93487bc -C extra-filename=-db0e30f3a93487bc --out-dir 'C:\msys64\tmp\rust\guessing_game\target\debug\build\winapi-db0e30f3a93487bc' -L 'dependency=C:\msys64\tmp\rust\guessing_game\target\debug\deps' --cap-lints allow`
     Running `rustc --crate-name build_script_build 'C:\Users\Administrator\.cargo\registry\src\github.com-1ecc6299db9ec823\libc-0.2.46\build.rs' --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="use_std"' -C metadata=f439455b17189f8e -C extra-filename=-f439455b17189f8e --out-dir 'C:\msys64\tmp\rust\guessing_game\target\debug\build\libc-f439455b17189f8e' -L 'dependency=C:\msys64\tmp\rust\guessing_game\target\debug\deps' --cap-lints allow`
     Running `C:\msys64\tmp\rust\guessing_game\target\debug\build\winapi-x86_64-pc-windows-gnu-cd7a6ff3618fa678\build-script-build`
     Running `C:\msys64\tmp\rust\guessing_game\target\debug\build\libc-f439455b17189f8e\build-script-build`
     Running `rustc --crate-name winapi_x86_64_pc_windows_gnu 'C:\Users\Administrator\.cargo\registry\src\github.com-1ecc6299db9ec823\winapi-x86_64-pc-windows-gnu-0.4.0\src\lib.rs' --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=b1bde479814dcaee -C extra-filename=-b1bde479814dcaee --out-dir 'C:\msys64\tmp\rust\guessing_game\target\debug\deps' -L 'dependency=C:\msys64\tmp\rust\guessing_game\target\debug\deps' --cap-lints allow -L 'native=C:\Users\Administrator\.cargo\registry\src\github.com-1ecc6299db9ec823\winapi-x86_64-pc-windows-gnu-0.4.0\lib'`
     Running `C:\msys64\tmp\rust\guessing_game\target\debug\build\winapi-db0e30f3a93487bc\build-script-build`
     Running `rustc --crate-name libc 'C:\Users\Administrator\.cargo\registry\src\github.com-1ecc6299db9ec823\libc-0.2.46\src\lib.rs' --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="use_std"' -C metadata=df7ade2be09a8644 -C extra-filename=-df7ade2be09a8644 --out-dir 'C:\msys64\tmp\rust\guessing_game\target\debug\deps' -L 'dependency=C:\msys64\tmp\rust\guessing_game\target\debug\deps' --cap-lints allow`
     Running `rustc --crate-name winapi 'C:\Users\Administrator\.cargo\registry\src\github.com-1ecc6299db9ec823\winapi-0.3.6\src\lib.rs' --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="minwindef"' --cfg 'feature="ntsecapi"' --cfg 'feature="profileapi"' --cfg 'feature="winnt"' -C metadata=7a3aa7d7c95390c7 -C extra-filename=-7a3aa7d7c95390c7 --out-dir 'C:\msys64\tmp\rust\guessing_game\target\debug\deps' -L 'dependency=C:\msys64\tmp\rust\guessing_game\target\debug\deps' --extern 'winapi_x86_64_pc_windows_gnu=C:\msys64\tmp\rust\guessing_game\target\debug\deps\libwinapi_x86_64_pc_windows_gnu-b1bde479814dcaee.rlib' --cap-lints allow --cfg 'feature="sspi"' --cfg 'feature="wincred"' --cfg 'feature="lsalookup"' --cfg 'feature="excpt"' --cfg 'feature="ktmtypes"' --cfg 'feature="basetsd"' --cfg 'feature="guiddef"' --cfg 'feature="vcruntime"' --cfg 'feature="subauth"' --cfg 'feature="windef"' --cfg 'feature="ntdef"' -l dylib=winapi_advapi32 -l dylib=winapi_credui -l dylib=winapi_kernel32 -l dylib=winapi_secur32 -L 'native=C:\Users\Administrator\.cargo\registry\src\github.com-1ecc6299db9ec823\winapi-x86_64-pc-windows-gnu-0.4.0\lib'`
   Compiling rand v0.4.3
     Running `rustc --crate-name rand 'C:\Users\Administrator\.cargo\registry\src\github.com-1ecc6299db9ec823\rand-0.4.3\src\lib.rs' --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="libc"' --cfg 'feature="std"' -C metadata=525ab3e86af69877 -C extra-filename=-525ab3e86af69877 --out-dir 'C:\msys64\tmp\rust\guessing_game\target\debug\deps' -L 'dependency=C:\msys64\tmp\rust\guessing_game\target\debug\deps' --extern 'winapi=C:\msys64\tmp\rust\guessing_game\target\debug\deps\libwinapi-7a3aa7d7c95390c7.rlib' --cap-lints allow -L 'native=C:\Users\Administrator\.cargo\registry\src\github.com-1ecc6299db9ec823\winapi-x86_64-pc-windows-gnu-0.4.0\lib'`
   Compiling rand v0.3.22
     Running `rustc --crate-name rand 'C:\Users\Administrator\.cargo\registry\src\github.com-1ecc6299db9ec823\rand-0.3.22\src\lib.rs' --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=028fc22332238648 -C extra-filename=-028fc22332238648 --out-dir 'C:\msys64\tmp\rust\guessing_game\target\debug\deps' -L 'dependency=C:\msys64\tmp\rust\guessing_game\target\debug\deps' --extern 'libc=C:\msys64\tmp\rust\guessing_game\target\debug\deps\liblibc-df7ade2be09a8644.rlib' --extern 'rand=C:\msys64\tmp\rust\guessing_game\target\debug\deps\librand-525ab3e86af69877.rlib' --cap-lints allow -L 'native=C:\Users\Administrator\.cargo\registry\src\github.com-1ecc6299db9ec823\winapi-x86_64-pc-windows-gnu-0.4.0\lib'`
   Compiling guessing_game v0.1.0 (file:///C:/msys64/tmp/rust/guessing_game)
     Running `rustc --crate-name guessing_game 'src\main.rs' --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=0ad3830cad379b28 -C extra-filename=-0ad3830cad379b28 --out-dir 'C:\msys64\tmp\rust\guessing_game\target\debug\deps' -C 'incremental=C:\msys64\tmp\rust\guessing_game\target\debug\incremental' -L 'dependency=C:\msys64\tmp\rust\guessing_game\target\debug\deps' --extern 'rand=C:\msys64\tmp\rust\guessing_game\target\debug\deps\librand-028fc22332238648.rlib' -L 'native=C:\Users\Administrator\.cargo\registry\src\github.com-1ecc6299db9ec823\winapi-x86_64-pc-windows-gnu-0.4.0\lib'`
    Finished dev [unoptimized + debuginfo] target(s) in 16.01s
     Running `target\debug\guessing_game.exe`
Guess the number!
Please input your guess.
123
You guessed: 123

@ddw360
Copy link

ddw360 commented Jan 5, 2019

@alexcrichton upgrading to WSL ubuntu 18.04, git 2.20.1, lastet rust and cargo nightly has not resolved.
Could this be related to: #1180 in any way?

@alexcrichton
Copy link
Member

This doesn't look related to certificate validation just yet, but your examples are also somewhat hard to follow for me :(. What caused the packages to actually be downloaded? It looks like in some cases connections to crates.io are disallowed but github is allowed. (I'm not really sure what's going on here...)

@weiby3
Copy link
Author

weiby3 commented Jan 7, 2019

The project comes from a tutorial.
The following is Cargo.toml.

[package]
name = "guessing_game"
version = "0.1.0"
authors = ["account"]

[dependencies]
rand = "0.3.14"

@ddw360
Copy link

ddw360 commented Jan 7, 2019

@alexcrichton I am trying to run the holochain stack and an example project
See:
https://developer.holochain.org/start.html
https://github.com/holochain/holochat-rust

The "hc package" and "hc test" commands issue the following "cargo":
"cargo build --release --target=wasm32=unknown-unknown"

and it fails - with SSL related issues - per the pastebin's I posted.

For me - what I have is problems specifically in Windows Subsystem for Linux. And pathing to cargo or hc are not the problem - they both come up correctly in bash.

In Windows 10 cmd.exe and powershell - no problems once I made sure that cargo and rustc were properly in the system path.

@weiby3 is likely having different root cause? But same resulting error - re: SSL and Spurious and git?

@d3sbar
Copy link

d3sbar commented Jan 19, 2019

@alexcrichton I am trying different projects in Windows Ubuntu 18.04 WSL - i.e. actix/examples. So cloned down the repo, go to the "hello-world" example and do cargo run. Get spurious network error. Firewall is turned off, no antivirus running, etc.

$ cargo build
    Updating crates.io index
warning: spurious network error (2 tries remaining): [7] Couldn't connect to server; class=Net (12)
warning: spurious network error (1 tries remaining): [7] Couldn't connect to server; class=Net (12)
error: failed to load source for a dependency on `actix`

Caused by:
  Unable to update registry `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  [7] Couldn't connect to server; class=Net (12)

@ehuss ehuss added the A-networking Area: networking issues, curl, etc. label Jan 31, 2019
@differui
Copy link

differui commented Mar 18, 2019

@d3sbar I stuck in same error. Fix that by removing [http_proxy] field in ~/.cargo/config.

@WindSoilder
Copy link

WindSoilder commented Aug 14, 2019

Got the same issue while Updating crate.io index... The error message is:

warning: spurious network error (2 tries remaining): HTTP parser error: stream ended at an unexpected time; class=Net (12)

But I think it's just caused by my Network problem...

I use wireshark to capture segments between my host and github(The ip address is 13.229.188.59).

From wireshark, I find the following phenomena:

  1. github have tried to send many Retransmission for the same segment and,
  2. my host is sending and sending back duplicate ACK.

It seems that my ACK can't reach github machine in time
It seems that it's just cause by network problem(like network congestion)

IMO, if there are stable Crates.io MIRROR exists in my region(Asia), the problem can be solved(by editing ~/.cargo/config).

Hope this information can help..

My OS: Mac 10.14.6
Cargo version: 1.36.0

@baburkin
Copy link

baburkin commented Aug 30, 2019

I got the same issue on Windows 7 and it looks like the reason behind that is cargo cannot find its way through our corporate NTLM proxy.

I was troubleshooting this with plain curl. When I try to run

curl https://github.com/rust-lang/crates.io-index

I get the response

curl: (56) Received HTTP code 407 from proxy after CONNECT

which implies that I need to authenticate in the proxy. By using curl with -vv option I can see that it tries to authenticate using NTLM:

...
Proxy-Authenticate: Negotiate
Proxy-Authenticate: NTLM

* Ignore NNNN bytes of response-body
* Received HTTP code 407 from proxy after CONNECT
* Closing connection 0
curl: (56) Received HTTP code 407 from proxy after CONNECT

Then what I did I added the following environment variables via Control Panel (the addresses are distorted on purpose):

HTTP_PROXY=http://ntlm-proxy.org.com:8080
HTTPS_PROXY=http://ntlm-proxy.org.com:8080
PROXY_USER=NT_DOMAIN\username
PROXY_PASS=the_password  <-- I know, not ideal, but see below

After that I was able to receive the crates index using the following command:

curl -vv --proxy-any -U : https://github.com/rust-lang/crates.io-index

It worked, it also worked with --proxy-ntlm instead of --proxy-any, but if I don't specify this parameter, I get the 407 error again. Instead of adding environment vars for user and password, I also was able to specify --proxy-user NT_DOMAIN\username and provide the password interactively - and it also worked.

So it looks like at the moment rust's cargo lacks support for NTLM proxy specifics, including authentication. Given that curl does support this, I think it is just a matter of adding this support in future versions.

Ideally, it would be nice to be able to to specify in ~/.cargo/config:

[http]
proxy = "host:port" # HTTP proxy to use for HTTP requests (defaults to none)
proxy-auth = "ntlm" # negotiate, basic, digest, etc... 
proxy-user = "username"
proxy-password = "password"
...          

@alexcrichton
Copy link
Member

Thanks for the investigation @baburkin!

This is unfortunately a pretty long a sprawling issue, mind opening a focused issue purely on supporting proxy authentication (aka NTLM)?

@Thesoul20
Copy link

Thesoul20 commented Aug 14, 2022

now i fixed it. in china, we need to set a china source for the crates: cd $HOME/.cargo nano config cat config

it shows:

[net] retry = 2 # network retries git-fetch-with-cli = true

[source.crates-io] registry = "https://github.com/rust-lang/crates.io-index" replace-with = 'ustc'

[source.ustc] registry = "git://mirrors.ustc.edu.cn/crates.io-index"

cd /path/to/some-rust-project/ cargo build --release

then u are set.

This worked for me.
But in the $HOME/.cargo directory, i have create a file named config.toml and write those command in the file.
OS: ubuntu 20.04 China.

@gingdotgithub
Copy link

not sure exactly what finally did it for me, but i plugged my laptop into ethernet and it worked fine first time after that. i wonder if its packet loss on the streams over my wifi. try it somewhere reliable and fast...

@rikonaka
Copy link

My situation is because my git proxy is configured, and I temporarily turned off the git proxy to fix it.

git config --global --unset http.proxy  
git config --global --unset https.proxy

It's save my life. 😘

@asears
Copy link

asears commented Feb 10, 2023

It's amazing this is still open in 2023! My fix was to allow the crate.exe through Windows Defender Firewall.

In my case I am setting up a new rust-up cargo install on a Windows 10 machine with latest git cli installed. I used the 64-bit Windows installer from the downloads page because the chocolatey installer appeared out of date with 1.25.1 instead of 1.25.2 and flagged with some scan warnings.

https://community.chocolatey.org/packages/rustup.install

Was testing the setup using the examples crate.

cargo install mdbook --vv

The --vv command didn't show any additional details.

Windows Firewall was not blocking the git client and was able to run both the inbuilt cargo git and use git cli git fetch options.

This worked fine both inside and outside of cargo, turning on and off the git fetch with cli option. Note the newer gh cli might be a good option to add to the list.

git fetch --force --update-head-ok https://github.com/rust-lang/crates.io-index +HEAD:refs/remotes/origin/HEAD -v

It was not the git step which was failing, it was the accessing of crates.io URL via a dynamic 6xxxx port.

Tested with curl and got following error

curl -vvv https://crates.io/api/v1/crates/mdbook/0.4.26/download

curl: (7) Failed to connect to crates.io port 443: Bad access

Allow an app through Windows Firewall might work, though I went the port route.
https://support.microsoft.com/en-us/windows/risks-of-allowing-apps-through-windows-defender-firewall-654559af-3f54-3dcf-349f-71ccd90bcc5c

I am using Malwarebytes Windows Firewall which added this pretty broad rule:
%USERPROFILE%.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\crate.exe
Allow
Out
Local ports: Any
Remote addresses: Any
Remote Ports: Any
Protocol: Any

Adding add rule to Windows Defender Firewall to the Windows installer or finding alternative approach might solve this particular issue.

williamdes added a commit to sudo-bot/docker-rustpython that referenced this issue Feb 22, 2023
williamdes added a commit to sudo-bot/docker-rustpython that referenced this issue Feb 22, 2023
williamdes added a commit to sudo-bot/docker-rustpython that referenced this issue Feb 22, 2023
@williamdes
Copy link

The only workaround that worked for me on my Dockerfile was

ENV CARGO_NET_GIT_FETCH_WITH_CLI=true

I tried all other workarounds but they did not work
Commit : sudo-bot/docker-rustpython@283fdda

@Create-Peace
Copy link

Hi, I had a similar issue recently. cargo build failed with this spurious network error message. I figured out that it was trying to clone a git repository as git://.... I tried git clone git://... manually and it really failed, however, git clone https://... worked. I added

[url "ssh://"]
    insteadOf = git://

to ~/.gitconfig as described here and then finally cargo worked, too.

Thannks. It works.

qexat added a commit to qexat/prideflag that referenced this issue Mar 10, 2023
@randall-coding
Copy link

randall-coding commented Mar 26, 2023

#  config file: ~/.cargo/config.toml
[net]
git-fetch-with-cli = true 
  1. Test if it works.

OS: Windows 10
cargo: 1.53.0 (4369396 2021-04-27) rustc: 1.53.0 (53cb7b09b 2021-06-17) git: 2.31.1.windows.1

This was the fix for me! Thank you very much. I experienced the problems when building with Docker (Alpine Base). It was a cross ARCH build. Interestingly when I was build native there was not an issue. If anyone points that into a direction that helps.

That solution helped me get through the initial download issue (listed by OP). But now it fails with "Peer certificate cannot be authenticated with given CA certificates (SSL certificate problem: certificate has expired)" on https://crates.io/api/v1/adler/1.0.2/download

MacOS 10.14.5
Cargo 1.70.0-nightly
Firewall is off.

I have 0 issues with this on Windows or Linux, but for some reason MacOS can't build.

UPDATE: Calling cargo run multiple times resolves the new ssl issue. #11670 Still strange, and would be nice if that wasn't required.

@jaques-sam
Copy link

This happens to me as well with a clean WSL Debian installation. First got it together with a Read-only file system; error upon rust installation. This worked again after shutting down WSL and try again. Now I get the same for cargo install upon downloading the crates.io index.

samja@TLV-TCS-C-SJ:/mnt/c/Users/C_SJ$ cargo install cargo-deb cargo-audit toml-cli ; rustup component add clippy rustfmt
    Updating crates.io index
warning: spurious network error (2 tries remaining): failed to create locked file '/home/samja/.cargo/registry/index/github.com-1ecc6299db9ec823/.git/objects/pack/pack_git2_986700b47da4idx.lock': Read-only file system; class=Os (2)
warning: spurious network error (1 tries remaining): failed to create temporary file '/home/samja/.cargo/registry/index/github.com-1ecc6299db9ec823/.git/objects/pack/pack_git2_c134288f68f3f534': Read-only file system; class=Os (2)
error: failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to create temporary file '/home/samja/.cargo/registry/index/github.com-1ecc6299db9ec823/.git/objects/pack/pack_git2_ec833f83de951fc7': Read-only file system; class=Os (2)
Bus error
Bus error

The command seems to corrupt WSL's filesystem completely, even got -bash: rm: command not found after running cargo install :-o

@vsTianhao
Copy link

I also have this problem without using any proxy

$ cargo run --verbose
    Updating crates.io index
warning: spurious network error (2 tries remaining): failed to send request: A connection with the server could not be established
; class=Os (2)
warning: spurious network error (1 tries remaining): failed to send request: A connection with the server could not be established
; class=Os (2)
error: failed to get `serde` as a dependency of package `tauri-app v0.0.0 (demo\tauri-app\src-tauri)`

Caused by:
  failed to load source for dependency `serde`

Caused by:
  Unable to update registry `crates-io`

Caused by:
  failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to send request: A connection with the server could not be established
  ; class=Os (2)

@helloninglei
Copy link

image

i also meet this problem , and the version is 1.70.0

rustup 1.26.0 (5af9b9484 2023-04-05) info: This is the version for the rustup toolchain manager, not the rustc compiler. info: The currently active rustcversion isrustc 1.70.0 (90c541806 2023-05-31)`

then i fixed it by update version to 1.68.0
rustup install 1.68.0 && rustup default 1.68.0

@ooooooops
Copy link

@weiby3 你好。 我也遇到这个问题,你解决该问题没有? 我至今未能解决。能否给点提示? 非常感谢你的回复

@briteming 后面没事了,我也不知道怎么解决的

我是把网断了重连就好了

@epage epage added the S-triage Status: This issue is waiting on initial triage. label Oct 30, 2023
@Hongqin-Li
Copy link

Hongqin-Li commented Nov 5, 2023

Hi, I had a similar issue recently. cargo build failed with this spurious network error message. I figured out that it was trying to clone a git repository as git://.... I tried git clone git://... manually and it really failed, however, git clone https://... worked. I added

[url "ssh://"]
    insteadOf = git://

to ~/.gitconfig as described here and then finally cargo worked, too.

Thannks. It works.

I use a similar solution with an additional "git@github.com" (for accessing private repo on github). It seems like the daemon service of git protocol doesn't work well with my proxy.

$ cat ~/.cargo/config.toml
[net]
git-fetch-with-cli = true

$ cat ~/.gitconfig
[url "ssh://git@github.com"]
	insteadOf = git://github.com

@ratankaliani
Copy link

Ran into the same issue as @Hongqin-Li, my .gitconfig was incorrect, replacing it fixed this issue!

@Demoevery
Copy link

Using gitoxide solved it for me
cargo +nightly -Zgitoxide run

@pengchenglv
Copy link

edit .cargo/config.toml as follows to disable proxy. It works for me

[http]
proxy = ""

@AirZED
Copy link

AirZED commented Nov 14, 2024

I believe I am having this same issue, but mine is from anchor

anchor build
    Updating crates.io index
warning: spurious network error (2 tries remaining): [92] Stream error in the HTTP/2 framing layer (HTTP/2 stream 3 was not closed cleanly: CANCEL (err 8)); class=Net (12)
warning: spurious network error (1 tries remaining): [92] Stream error in the HTTP/2 framing layer (HTTP/2 stream 7 was not closed cleanly: CANCEL (err 8)); class=Net (12)
error: Unable to update registry `crates-io`

Caused by:
  failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  network failure seems to have happened
  if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  [92] Stream error in the HTTP/2 framing layer (HTTP/2 stream 11 was not closed cleanly: CANCEL (err 8)); class=Net (12)

When I edit my .cargo/config.toml file to

[http]
timeout =10000
low-speed-limit = 1000
multiplexing = false
proxy = ""


[net]
git-fetch-with-cli = true

I have this instead

anchor build
    Updating crates.io index
remote: Enumerating objects: 585836, done.
remote: Counting objects: 100% (8628/8628), done.
remote: Compressing objects: 100% (2932/2932), done.
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
error: Unable to update registry `crates-io`

Caused by:
  failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  process didn't exit successfully: `git fetch --force --update-head-ok 'https://github.com/rust-lang/crates.io-index' '+HEAD:refs/remotes/origin/HEAD'` (exit status: 128)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-networking Area: networking issues, curl, etc. C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests