如何调试挂在“更新 crates.io 索引”处的 `cargo build`?

问题描述 投票:0回答:3

在我的 RLS 插件和终端构建之间发生一些冲突后,我的 Rust 项目不再构建。我在网上搜索并找到了删除我的

~/.cargo/registry/index/*
的建议,但之后我什至无法构建任何项目。

现在构建总是停止在

更新 crates.io 索引

传递

--verbose
选项没有帮助,所以我什至不知道它是否正在死亡。接下来我应该做什么?如何调试这个问题?

rust rust-cargo
3个回答
6
投票

删除

~/.cargo/.package-cache
文件。


0
投票

更改 ~/.cargo/config 中的货物源。这对我有用。

例如:

[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"

0
投票

我建议不要擦除任何文件夹,因为活动数据是带有一些加密注册表数据的 git 存储库,而常见原因是与 GitHub 通信的网络问题。无论问题只是连接速度慢还是基础设施受到严重破坏,擦除文件夹都可能会删除您已下载的正确数据,然后通过无响应的链接重新下载这些数据。如果问题是本地数据损坏,那么擦除文件夹是有意义的。

听起来,cargo 缺少一个重要的 git 网络活动日志记录工具,除非更熟悉它的人知道更多。

以下是我在不了解货物的情况下诊断此问题的方法。看来如果用户知道货物登记的话会更快。

# ran failing process in background
$ cargo update &
     Updating crates.io index
[1] 8129

# store PID of background process in variable
$ CARGO_PID=$1

# listed files accessed by process
$ ls -l /proc/$CARGO_PID/fd
total 0
lrwx------. 1 user user 64 Nov  7 06:19 0 -> /dev/pts/377
lrwx------. 1 user user 64 Nov  7 06:19 1 -> /dev/pts/377
lrwx------. 1 user user 64 Nov  7 06:19 10 -> 'socket:[45370067]'
lrwx------. 1 user user 64 Nov  7 06:19 11 -> 'socket:[45383920]'
lrwx------. 1 user user 64 Nov  7 06:19 2 -> /dev/pts/377
lrwx------. 1 user user 64 Nov  7 06:19 3 -> /home/user/.cargo/.package-cache
lr-x------. 1 user user 64 Nov  7 06:19 4 -> /home/user/.cargo/registry/index/github.com-1ecc6299db9ec823/.git/objects/pack/pack-4bac04bfb4c5de794c1dd0a40d86cfc18f9eb5ae.pack
lrwx------. 1 user user 64 Nov  7 06:19 5 -> 'socket:[45370061]'
lr-x------. 1 user user 64 Nov  7 06:19 6 -> /home/user/.pki/nssdb/cert9.db
lr-x------. 1 user user 64 Nov  7 06:19 7 -> /home/user/.pki/nssdb/key4.db
lr-x------. 1 user user 64 Nov  7 06:19 8 -> /etc/pki/nssdb/cert9.db
lr-x------. 1 user user 64 Nov  7 06:19 9 -> /etc/pki/nssdb/key4.db

# it's working with a git repositry, visited git repository
$ cd /home/user/.cargo/registry/index/github.com-1ecc6299db9ec823/.git

# i then looked various common places for the remote it was fetching from.
# FETCH_HEAD showed this in one run, but in another FETCH_HEAD was empty
# I then found it in the logs folder.
# you could also use a network utility, strace, or debug or patch cargo
$ cat config
[core]
    bare = false
    repositoryformatversion = 0
    filemode = true
    logallrefupdates = true
$ ls
config  description  FETCH_HEAD  HEAD  hooks  info  logs  objects  refs
$ cat HEAD
ref: refs/heads/main
$ cat FETCH_HEAD
$ ls logs
refs
$ ls logs/refs/
remotes
$ ls logs/refs/remotes/
origin
$ ls logs/refs/remotes/origin/
HEAD
$ cat logs/refs/remotes/origin/HEAD
0000000000000000000000000000000000000000 cd2e0d3249278088bdb2c8ab9227c1e745977d2a John Doe <[email protected]> 1671547379 -0500   fetch https://github.com/rust-lang/crates.io-index
cd2e0d3249278088bdb2c8ab9227c1e745977d2a 995b889318272a6dbc9591a688fc6d0053fbdacf John Doe <[email protected]> 1671550295 -0500   fetch https://github.com/rust-lang/crates.io-index
995b889318272a6dbc9591a688fc6d0053fbdacf e6ca1cbd89a020cfccfb741738b47d905ec51a38 John Doe <[email protected]> 1671965624 -0500   fetch https://github.com/rust-lang/crates.io-index
e6ca1cbd89a020cfccfb741738b47d905ec51a38 9dfcadd951ddd8b5b311b0653bf09069b62594a3 John Doe <[email protected]> 1672045603 -0500   fetch https://github.com/rust-lang/crates.io-index
9dfcadd951ddd8b5b311b0653bf09069b62594a3 2df4156cfe1fba11c11f8b1956ac8c3012da94da John Doe <[email protected]> 1672051948 -0500   fetch https://github.com/rust-lang/crates.io-index
2df4156cfe1fba11c11f8b1956ac8c3012da94da 53c0024ba8565070cc0644cc4417d81e2d588aac John Doe <[email protected]> 1672324569 -0500   fetch https://github.com/rust-lang/crates.io-index
53c0024ba8565070cc0644cc4417d81e2d588aac 2bdf23bbb3e8e1752ab88485168330751d8d9e49 John Doe <[email protected]> 1683666817 -0400   fetch https://github.com/rust-lang/crates.io-index

现在(如果您滚动到上方右下角),人们可以看到它可能正在从

git fetch
执行
https://github.com/rust-lang/crates.io-index

# terminate background process
$ fg
cargo update    (wd: ~/src/project)
^C

# try fetching from its url
$ git fetch --progress --verbose https://github.com/rust-lang/crates.io-index
POST git-upload-pack (117 bytes)
POST git-upload-pack (958 bytes)
POST git-upload-pack (967 bytes)
remote: Enumerating objects: 626476, done.
remote: Counting objects: 100% (35613/35613), done.
remote: Compressing objects: 100% (1310/1310), done.
Receiving objects:  98% (615100/626476), 399.19 MiB | 1.36 MiB/s
# hangs at 98%, no more output

故障排除已简化为从此存储库诊断 git fetch。

就我个人而言,我的内核随后开始出现有关我的 WiFi 驱动程序的错误,这可能是一个不幸的巧合,也可能是恶意活动的迹象。更常见的是,我的可用磁盘空间变得非常低,并且我在与 github.com 通信时遇到网络问题。

© www.soinside.com 2019 - 2024. All rights reserved.