Skip to content

Cannot update crates.io-index properly #76

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

Closed
onur opened this issue Oct 29, 2016 · 21 comments · Fixed by #77
Closed

Cannot update crates.io-index properly #76

onur opened this issue Oct 29, 2016 · 21 comments · Fixed by #77
Labels
C-bug Category: This is a bug

Comments

@onur
Copy link
Member

onur commented Oct 29, 2016

Docs.rs started failing to update crates.io-index with error messages:

2016/10/28 01:36:27 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/.git/refs/heads/master': Too many open files
2016/10/28 22:39:17 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/1/a' for writing: Too many open files
2016/10/29 06:10:14 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [9/-3] Object not found - no match for id (59db1781fd28117680e949829f8d5b2b4b96475c)
2016/10/29 08:40:36 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [9/-3] Object not found - no match for id (59db1781fd28117680e949829f8d5b2b4b96475c)
2016/10/29 09:25:42 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [9/-3] Object not found - no match for id (73cb7a3d3a9ab35eabe673ba337c4546b1cc789e)
2016/10/29 10:55:54 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [9/-3] Object not found - no match for id (e4d7586ac14bd8053e11777dac754257063a8410)
2016/10/29 11:10:57 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [9/-3] Object not found - no match for id (49c61a0cd4c8b909a9b67f57d08c6cb0e9a737d4)
...
2016/10/29 22:06:09 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [9/-3] Object not found - no match for id (e874b5b0158fe0d6173d66237d9a6d2189ec3819)

I started working on some workarounds until I investigate this issue. Docs.rs cannot build new crates for now.

@onur onur added the grave label Oct 29, 2016
@BurntSushi
Copy link
Member

@onur Thank you for working on this! :-)

onur added a commit that referenced this issue Oct 30, 2016
So we can build world in a old fashion way in case of emergency
(Ref: #76)
onur added a commit that referenced this issue Oct 31, 2016
Docs.rs is currently using crates.io-index git repository to resolve
new crates. But method used in docs.rs isn't very stable and doesn't
work all the time. Using crates.io web API will solve this issue and
bring more stable way to resolve new crates.

Fixes: #76, #60
@onur onur closed this as completed in #77 Nov 1, 2016
@onur onur added C-bug Category: This is a bug and removed grave labels Nov 2, 2016
@onur
Copy link
Member Author

onur commented Nov 2, 2016

This issue still exists and I am not sure what is causing this. This issue is occurring when cargo trying to download a crate. And now it started happening when cargo is trying to update registry index.

Main issue is Too many open files:

2016/10/28 01:36:27 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/.git/refs/heads/master': Too many open files
2016/10/28 07:52:12 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/.git/refs/heads/master': Too many open files
2016/10/28 08:22:17 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/.git/refs/heads/master': Too many open files
2016/10/28 20:39:00 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/.git/refs/heads/master': Too many open files
2016/10/28 22:09:12 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/.git/refs/heads/master': Too many open files
2016/10/28 22:24:14 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/.git/refs/heads/master': Too many open files
2016/10/28 22:39:17 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/1/a' for writing: Too many open files
2016/10/29 06:25:17 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/.git/refs/heads/master': Too many open files
2016/10/29 06:40:20 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/1/a' for writing: Too many open files
2016/10/29 07:40:27 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/.git/refs/heads/master': Too many open files
2016/10/29 07:55:30 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/1/a' for writing: Too many open files
2016/10/29 08:10:31 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/1/a' for writing: Too many open files
2016/10/29 08:25:33 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/1/a' for writing: Too many open files
2016/11/02 13:35:21 [ERROR] cratesfyi::utils::daemon: Failed to update sources: [2/-1] Could not open '/srv/cratesfyi/.cargo/registry/index/git.cakeli.workers.dev-1ecc6299db9ec823/.git/refs/heads/master': Too many open files
2016/11/02 13:50:50 [ERROR] cratesfyi::utils::daemon: Failed to update sources: [2/-1] Could not open '/srv/cratesfyi/.cargo/registry/index/git.cakeli.workers.dev-1ecc6299db9ec823/1/a' for writing: Too many open files
2016/11/02 14:07:02 [ERROR] cratesfyi::utils::daemon: Failed to update sources: [2/-1] Could not open '/srv/cratesfyi/.cargo/registry/index/git.cakeli.workers.dev-1ecc6299db9ec823/.git/refs/heads/master': Too many open files
2016/11/02 14:32:30 [ERROR] cratesfyi::utils::daemon: Failed to update sources: [2/-1] Could not open '/srv/cratesfyi/.cargo/registry/index/git.cakeli.workers.dev-1ecc6299db9ec823/.git/refs/heads/master': Too many open files
2016/11/02 14:37:32 [ERROR] cratesfyi::utils::daemon: Failed to update sources: [2/-1] Could not open '/srv/cratesfyi/.cargo/registry/index/git.cakeli.workers.dev-1ecc6299db9ec823/.git/refs/heads/master': Too many open files
2016/11/02 14:42:34 [ERROR] cratesfyi::utils::daemon: Failed to update sources: [2/-1] Could not open '/srv/cratesfyi/.cargo/registry/index/git.cakeli.workers.dev-1ecc6299db9ec823/.git/refs/heads/master': Too many open files
2016/11/02 14:57:42 [ERROR] cratesfyi::utils::daemon: Failed to update sources: [2/-1] Could not open '/srv/cratesfyi/.cargo/registry/index/git.cakeli.workers.dev-1ecc6299db9ec823/1/a' for writing: Too many open files
2016/11/02 15:02:44 [ERROR] cratesfyi::utils::daemon: Failed to update sources: [2/-1] Could not open '/srv/cratesfyi/.cargo/registry/index/git.cakeli.workers.dev-1ecc6299db9ec823/1/a' for writing: Too many open files

Docs.rs had a huge ~/.cargo. Size of ~/.cargo directory was around ~100GB. I removed registry and docs.rs immediately started building crates. I'll monitor docs.rs and see if this issue happens again. And I'll add some code to remove registry (or src in registry) if my solution works.

@onur onur reopened this Nov 2, 2016
@BurntSushi
Copy link
Member

Is a file descriptor getting leaked somewhere? Or is directory traversal being done naively somewhere?

@BurntSushi
Copy link
Member

@alexcrichton might have ideas

@alexcrichton
Copy link
Member

Hm yeah this may just be a standard "some file is being held open for too long" issue perhaps?

@BurntSushi
Copy link
Member

Does cargo do any directory traversal?

@alexcrichton
Copy link
Member

AFAIK no, but I haven't audited it for something like this. Is this error coming from Cargo?

@onur
Copy link
Member Author

onur commented Nov 10, 2016

@alexcrichton last part of the messages are coming from git2 crate:

[2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/.git/refs/heads/master': Too many open files
[2/-1] Could not open '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/1/a' for writing: Too many open files
[2/-1] Could not open '/srv/cratesfyi/.cargo/registry/index/git.cakeli.workers.dev-1ecc6299db9ec823/1/a' for writing: Too many open files

I am not sure what was the cause, this only happened when docs.rs tried to update crates.io-index repository and when cargo tried to update registry. Cleaning ~/.cargo/registry fixed this issue for now, but I am sure it will happen again since docs.rs is using cargo to download and cache tons of crates.

@alexcrichton
Copy link
Member

I guess this could be a bug with libgit2 perhaps? Holding open too many file descriptors on large repos? Unsure though.

hadronized pushed a commit to hadronized/docs.rs that referenced this issue Nov 30, 2016
So we can build world in a old fashion way in case of emergency
(Ref: rust-lang#76)
hadronized pushed a commit to hadronized/docs.rs that referenced this issue Nov 30, 2016
Docs.rs is currently using crates.io-index git repository to resolve
new crates. But method used in docs.rs isn't very stable and doesn't
work all the time. Using crates.io web API will solve this issue and
bring more stable way to resolve new crates.

Fixes: rust-lang#76, rust-lang#60
@shssoichiro
Copy link

It seems like this may still be an issue. It looks like docs.rs hasn't pulled any crates in 10 hours, including a crate that I released last night.

@onur
Copy link
Member Author

onur commented Dec 21, 2016

@shssoichiro docs.rs got stuck while building zxcvbn 0.1.0

@shssoichiro
Copy link

Is there something wrong with that crate that's causing the build to hang? I didn't mean to break docs.rs by publishing a crate 😲

@onur
Copy link
Member Author

onur commented Dec 21, 2016

@shssoichiro no your crate is fine, idk what was the cause but it only got stuck for x86_64-pc-windows-msvc target, I tried to rebuild now and it finished in less than a minute.

@Byron
Copy link
Member

Byron commented Dec 25, 2016

Given the latest issues (see #89) I believe it would be best to go back to using the crates index directly, and invest some time into figuring out where the file handle is leaked. If in doubt, one could also set it up as a separate binary that just outputs the required information on stdout.

@onur
Copy link
Member Author

onur commented Feb 18, 2017

@alexcrichton I am still having this issue:

2017/02/18 15:44:16 [ERROR] cratesfyi::utils::daemon: Failed to get new crates: [2/-1] Failed to create locked file '/srv/cratesfyi/cratesfyi-prefix/crates.io-index/.git/objects/pack/pack_git2_YZidx.lock': Too many open files

This error message is coming from git2 crate. Docs.rs is using crates-index-diff to update crates.io-index git repository. When this bug occurs, git2 crate is trying to open bunch of pack files such as:

cratesfyi 28000 cratesfyi 1012r   REG      8,17     14146 24381195 /srv/cratesfyi/cratesfyi-prefix/crates.io-index/.git/objects/pack/pack-eddbb128457be67b65ee219f42d36d98219bc098.pack
cratesfyi 28000 cratesfyi 1013r   REG      8,17     13230 24381185 /srv/cratesfyi/cratesfyi-prefix/crates.io-index/.git/objects/pack/pack-a565be350b66fbf576356595a8836d2f3798c326.pack
cratesfyi 28000 cratesfyi 1014r   REG      8,17     14097 24381191 /srv/cratesfyi/cratesfyi-prefix/crates.io-index/.git/objects/pack/pack-cf2a637ba7d55e6b0efa7d9ed3883ffc54e9b62f.pack
cratesfyi 28000 cratesfyi 1015r   REG      8,17     13481 24381189 /srv/cratesfyi/cratesfyi-prefix/crates.io-index/.git/objects/pack/pack-1276ac8f603d511d179713aa577c012f3918ddcd.pack
...
$ lsof -p 28000 | grep 'pack$' | wc -l
1758

Doing git pull manually in repository is fixing this issue but I am not sure what is causing in first place. After running git pull all pack files are getting removed but looks like git2 crate is not removing them. @Byron @alexcrichton do you have any ideas?

@alexcrichton I believe cargo also have this issue:

$ ls ~/.cargo/registry/index/git.cakeli.workers.dev-1ecc6299db9ec823/.git/objects/pack/*pack | wc -l
1701

After it's reaching a certain point, cargo starts failing to update registry.

@Byron
Copy link
Member

Byron commented Feb 18, 2017

tl;dr: I would try running git gc via Command on the crates-io-index repository after each fetch.

A very interesting observation! Initially I thought it might be a resource leak, but that does not seem to be the case as the repository is not persisting in memory.

As every fetch seems to (have a chance to) generate a small pack, and as using the repository at all seems to want to open all of them at the same time, we run into issues. Maybe the mempack feature is responsible for that.

My intuition would be to initiate a garbage collection (like git gc) after each fetch manually - it seems that the git2::Repository does not support that directly, nor does libgit2. However, it certainly can be implemented in some way using the PackBuilder, or one could just call out to the git program directly to keep things very simple and avoid reimplementing gc in Rust.

@onur
Copy link
Member Author

onur commented Feb 18, 2017

@Byron running git gc will only fix crates-index-diff but I am also getting same error from cargo via update_sources.

@Byron
Copy link
Member

Byron commented Feb 18, 2017

@onur I thought cargo has the same issue, and thus it should also be fixable by a git gc invocation (provided we can assume that there is no file-handle leakage as the Repository instances do not persist).

@alexcrichton
Copy link
Member

Hm I'm surprised Cargo users haven't run into this yet, are there differences to what's going on? Maybe multiple Repository instances to the index open simultaneously in one process?

Perhaps the fd limit could just be raised?

(sorry I don't know how to fix this nor why it's happening)

@onur onur mentioned this issue Mar 4, 2017
@onur
Copy link
Member Author

onur commented Mar 9, 2017

@Byron based on your suggestion I write a simple cron job to run git gc on repositories. I believe everything is working fine now.

@jyn514
Copy link
Member

jyn514 commented Feb 1, 2020

I haven't ever seen this error, I think git gc fixed it.

@jyn514 jyn514 closed this as completed Feb 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants