Unable to cargo build/run/update/install due to SSL error: received early EOF

I can't seem to be able to install, build or update any external crates with Cargo. I have already reinstalled the entire toolchain with rustup and I have tried with both stable-x86_64-unknown-linux-gnu (1.51.0) and nightly-x86_64-unknown-linux-gnu (1.53.0).

When trying cargo build in my project directory, I get the following:

Updating crates,io index
error: failed to get tar as a dependency of package codecom v0.1.0 (/home/mak/Projects/rust/codecom)

Caused by:
failed to load source for dependency tar

Caused by:
Unable to update registry crates,io-index

Caused by:
failed to fetch 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:
SSL error: received early EOF; class=Ssl (16); code=Eof (-20)

When I follow on the suggestion and do
export CARGO_NET_GIT_FETCH_WITH_CLI=true
I then get the following instead:

Updating crates,io index
error: failed to get tar as a dependency of package codecom v0.1.0 (/home/mak/Projects/rust/codecom)

Caused by:
failed to load source for dependency tar

Caused by:
Unable to update registry crates,io-index

Caused by:
failed to fetch crates,io-index

Caused by:
process didn't exit successfully: git fetch --force --update-head-ok 'github.com/rust-lang/crates,io-index' 'refs/heads/master:refs/remotes/origin/master' 'HEAD:refs/remotes/origin/HEAD' (exit code: 128)
--- stderr
error: RPC failed; curl 56 GnuTLS recv error (-9): A TLS packet with unexpected length was received.
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

As stated, I have reinstalled the entire Rust toolchain via rustup and I have also reinstalled git and checked that my certificates are up-to-date. I and using VS Code with the Rust extension however these results are the same regardless of terminal session. My distro is an updated Ubuntu 16.04 LTS.

I hope that there is something obvious I am missing as I can't seem to find anything about this. As it stands, I am unable to even update the crates index for my cargo let alone use external crates.

If you can help, thank you.

I should note: I've had to mangle the links here because this site doesn't currently like me posting more than 2.

Are you behind a proxy? Are you able to reach https://github.com with curl? (something like curl -o /dev/null https://github.com/) Are you able to clone the registry with git by itself? (something like git fetch https://github.com/rust-lang/crates.io-index.git)

Some similar issues:

1 Like

Try this
Step1 : Uninstall rust
rustup self uninstall
Step2 : Install rust using
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Step 3 : Restart you computer then check the rust version

This problem may be occur because you may mess up with .cargo folder in home directory

The problem was seemingly with reindexing crates.io for cargo. Turns out my internet connection was faulty and somehow proxied downloads incorrectly. After posting it cut off for a day. Thanks for the suggestion though - I hadn't tried that. Would be good to replicate it and find out if it worked.

Internet connection/DSL mess-up after posting this: connection entirely cut off for a day. Seems like that had an effect on my downloads. I was able to reach github with curl but downloading the crates index repo over http and ssh seemed to cause the other end to refuse connection to/prematurely close on me. It's working now that /that/ issue resolved though. Would give your suggestion a try if it happened again.