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

Failed to mmap #2808

Closed
miedzinski opened this issue Jun 27, 2016 · 35 comments
Closed

Failed to mmap #2808

miedzinski opened this issue Jun 27, 2016 · 35 comments

Comments

@miedzinski
Copy link

I can't install anything with cargo.

$ cargo install --verbose rustfmt
    Updating registry `https://github.com/rust-lang/crates.io-index`
error: failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  [2/-1] Failed to mmap. Could not write data: Invalid argument

or by putting dependency in Cargo.toml

$ cat Cargo.toml
[package]
name = "test"
version = "0.1.0"
authors = ["test"]

[dependencies]
rustfmt = "0.5"
$ cargo build --verbose
    Updating registry `https://github.com/rust-lang/crates.io-index`
error: 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:
  [2/-1] Failed to mmap. Could not write data: Invalid argument
$ rustc --version
rustc 1.9.0 (e4e8b6668 2016-05-18)
$ cargo --version
cargo 0.10.0-nightly (10ddd7d 2016-04-08)

I am running up-to-date Ubuntu 16.04 LTS.

@alexcrichton
Copy link
Member

Whoa, haven't seen that one before! Are you perhaps running on a system that's running low on memory? It may be worth running strace as well to take a look at the parameters to the mmap call that's failing.

@miedzinski
Copy link
Author

miedzinski commented Jun 27, 2016

mmap(NULL, 11, PROT_READ|PROT_WRITE, MAP_SHARED, 5, 0) = -1 EINVAL (Invalid argument)

There is also one thing I forgot to mention and it may be the cause. That Ubuntu is inside VirtualBox 5.0.22 on Windows host. I'm using this setup for years and never had any problems, so I haven't thought about mentioning this in first place.

Definitely RAM usage isn't an issue (host or guest).


This may be related to #1578. My whole home dir is on vbox shared folder.

$ df -T
Filesystem     Type     1K-blocks      Used Available Use% Mounted on
udev           devtmpfs    490492         0    490492   0% /dev
tmpfs          tmpfs       101592      3272     98320   4% /run
/dev/sda1      ext4      32894832   8020564  23180268  26% /
tmpfs          tmpfs       507956         8    507948   1% /dev/shm
tmpfs          tmpfs         5120         0      5120   0% /run/lock
tmpfs          tmpfs       507956         0    507956   0% /sys/fs/cgroup
/home          vboxsf   524287996 220802040 303485956  43% /home/dominik
tmpfs          tmpfs       101592         0    101592   0% /run/user/1000

I'm not sure whether it's important, but i'm using git from guest without any issues.


libgit2/git2go#194 (comment) looks familiar.

@alexcrichton
Copy link
Member

Interesting! Could you gist the full syscall log as well? It looks like it's attempting to map whatever file descriptor 5 is, and it may be good to see how that's in play

@miedzinski
Copy link
Author

https://paste.ubuntu.com/17997204/

I guess it's /home/dominik/.cargo/registry/index/github.aaakk.us.kg-88ac128001ac3a9a/.git/objects/pack/pack_git2_iAED2h/

@alexcrichton
Copy link
Member

cc @carlosmn, does this sound familiar in libgit2?

It looks like the relevant syscalls leading up to the failure here are:

open("/home/dominik/.cargo/registry/index/github.aaakk.us.kg-88ac128001ac3a9a/.git/objects/pack/pack_git2_iAED2h", O_RDWR|O_CREAT|O_EXCL, 0600) = 5
[..]
lseek(5, 10, SEEK_SET)                  = 10
write(5, "P", 1)                        = 1
mmap(NULL, 11, PROT_READ|PROT_WRITE, MAP_SHARED, 5, 0) = -1 EINVAL (Invalid argument)

I think that cargo is using libgit2 0.2.23 right now FWIW

@carlosmn
Copy link

It looks to be the same issue as the one in the git2go tracker. The VirtualBox filesystem does not like something we're doing, but it's not clear what.

It's possible that it doesn't support files with holes even though it doesn't actually complain about them, or maybe it's just with mmap. Someone reported the tests run fine, which is really odd as it's the same code. It probably doesn't help that it seems to be translating unix calls into Windows filesystem calls, which breaks the assumptions we're making in the library.

@miedzinski can you clone fine if you're on VBox but without a shared home dir?

@miedzinski
Copy link
Author

@carlosmn I can use all git commands (including clone) on vboxsf. If you are asking about libgit2 (which git binary doesn't use, right?), then you have to wait few hours until I come back home and try it with cargo.

@miedzinski
Copy link
Author

@carlosmn, @alexcrichton, it works flawlessly.

$ cargo install rustfmt
    Updating registry `https://github.com/rust-lang/crates.io-index`
 Downloading rustfmt v0.5.0
# downloading and compiling lots of crates
  Installing /home/libgit/.cargo/bin/rustfmt
  Installing /home/libgit/.cargo/bin/cargo-fmt
$ ~/.cargo/bin/rustfmt -V
0.5.0

This is the same virtual machine, but this time cargo directory is on ext4.

@alexcrichton
Copy link
Member

@miedzinski could you try compiling this and see if it runs into the same error when cloning onto a shared directory?

#include <git2.h>
#include <assert.h>

int main() {
  git_repository *repo;
  assert(git_libgit2_init() == 1);
  assert(git_clone(&repo,
                   "https://github.com/rust-lang/crates.io-index",
                   "crates.io-index",
                   NULL) == 0);
}

@miedzinski
Copy link
Author

a.out: test.c:10: main: Assertion git_clone(&repo, "https://github.com/rust-lang/crates.io-index", "crates.io-index", NULL) == 0' failed.`

Built against 0.24.1-2 from Ubuntu repository.

@alexcrichton
Copy link
Member

@miedzinski could you try using strace as well to ensure that it's failing with the same mmap error as before?

@miedzinski
Copy link
Author

@alexcrichton
Copy link
Member

Hm it's not clear from that gist that it's the same mmap error you're hitting with Cargo. It's also doing a different operation with a clone rather than a fetch, so that may be factoring in as well. It may be worth poking around various incantations to see if it can be reproduced with just libgit2 so we can report the bug upstream.

@carlosmn
Copy link

That error looks like libgit2 was not built with HTTPS support. Trying with git:// might provide more reliable results.

I've opened libgit2/libgit2#3845 to track this upstream, but I'm not sure that there's a fix that doesn't involve a lot of yak shaving so we don't need to read the data back from disk.

@alexcrichton
Copy link
Member

Sounds good to me, thanks @carlosmn!

@miedzinski
Copy link
Author

miedzinski commented Jun 29, 2016

@carlosmn, there is definitely something wrong here. I have changed this code to:

#include <git2.h>
#include <assert.h>

int main() {
  git_repository *repo;
  assert(git_libgit2_init() == 1);
  assert(git_clone(&repo,
                   "git://[email protected]:rust-lang/crates.io-index.git"
                   "crates.io-index",
                   NULL) == 0);
}

and assertion was failing as well. I have tried different URLs (like [email protected]:rust-lang/crates.io-index.git) and after few tries I saw crates.io-index directory (it could have been there since first execution though). And what's weird, I couldn't delete it -- rm was complaining that it can't remove pack_xxx file with error Operation not permitted. I have deleted it straight from Windows, but since then I couldn't make libgit2 to create this directory again.
Like I said few times, official git binary produces valid repositories.

@alexcrichton, is it possible to change cargo directory location? It seems like a good workaround. If not, I can always mount ext4 filesystem on ~/.cargo/.

edit: symlink is sufficient. :)

@carlosmn
Copy link

"git://[email protected]:rust-lang/crates.io-index.git"

That's not going to work, since you're aksing for rust-lang to be the port. You're mixing URLs with scp/rsync syntax.

"Operation not permitted" is another error that seems to come from weird interactions between vboxfs and Windows. I'm not sure where the error comes from in that case.

@miedzinski
Copy link
Author

It seems you are right. I have found which URL produced these files.

#include <git2.h>
#include <assert.h>

int main() {
  git_repository *repo;
  assert(git_libgit2_init() == 1);
  assert(git_clone(&repo,
                   "git://github.com/rust-lang/crates.io-index",
                   "crates.io-index",
                   NULL) == 0);
}

Unlike https version, this creates crates.io-index directory:

$ tree -a crates.io-index/
crates.io-index/
└── .git
    ├── objects
    │   └── pack
    │       └── pack_git2_Hfr6Me
    └── refs
        ├── heads
        └── tags

6 directories, 1 file

But assertion still fails. This time strace shows that unlink call returns Operation not permitted. I can't remove it from inside virtual machine as well.

# rm -rf crates.io-index/
rm: cannot remove 'crates.io-index/.git/objects/pack/pack_git2_Hfr6Me': Operation not permitted

strace ouput: https://paste.ubuntu.com/18115479/

@alexcrichton
Copy link
Member

alexcrichton commented Jun 29, 2016

Oh that looks like it's a reproduction, from the strace logs:


open("/home/dominik/Projects/crates.io-index/.git/objects/pack/pack_git2_7Ak1Xv", O_RDWR|O_CREAT|O_EXCL, 0600) = 5
[..]
lseek(5, 10, SEEK_SET)                  = 10
write(5, "P", 1)                        = 1
mmap(NULL, 11, PROT_READ|PROT_WRITE, MAP_SHARED, 5, 0) = -1 EINVAL (Invalid argument)

@miedzinski
Copy link
Author

Well, there is problem with chmods on vboxsf, because Windows doesn't support them. Using chmod (root or normal user) has no effect. My entry in /etc/fstab looks like this:

home /home/dominik vboxsf defaults,uid=dominik,gid=dominik,fmask=077,dmask=077 0 0

Which means all files have chmod 700 inside my $HOME directory.

@lilith
Copy link
Contributor

lilith commented Aug 19, 2016

With Rust 1.11 & cargo 1.12, I get what appears to be a related error:

    Updating registry`https://github.com/rust-lang/crates.io-index`
warning: spurious network error (2 tries remaining): [2/-1] Failed to mmap. Could not write data: Invalid argument
warning: spurious network error (1 tries remaining): [2/-1] Failed to mmap. Could not write data: Invalid argument
error: failed to update registry https://github.com/rust-lang/crates.io-index

@splix
Copy link

splix commented Feb 5, 2017

I have same issue with cargo 1.16 and rust 1.15. The only difference that I'm using KVM+QEMU virtual machine, but with shared home folder as well. My host machine is on Debian, as well as guest.
If I change home folder to local, instead of shared, all works fine.

@Nercury
Copy link

Nercury commented Feb 14, 2017

I think I have hit the same issue on OSX while wanting to be clever and reuse cargo registry between builds on a docker:

docker run \
    -v $(pwd)/build/.cargo:/root/.cargo \
    -v $(pwd):/source jimmycuadra/rust:1.15.0 \
    /bin/bash -c "cargo build --release"
    Updating registry `https://github.com/rust-lang/crates.io-index`
warning: spurious network error (2 tries remaining): [2/-1] Failed to mmap. Could not write data: Invalid argument
warning: spurious network error (1 tries remaining): [2/-1] Failed to mmap. Could not write data: Invalid argument
error: failed to fetch `https://github.com/rust-lang/crates.io-index`

@miedzinski
Copy link
Author

This issue is mostly related to vboxsf filesystem. Consider running cargo with strace (look at @alexcrichton comments above) and report to libgit2/libgit2#3845 if it fails the same way on overlayfs (or whatever docker is using right now) or create new issue.

@jml
Copy link

jml commented Mar 3, 2017

@Nercury Did you come up with a clever way of re-using registry without triggering this bug?

@Nercury
Copy link

Nercury commented Mar 3, 2017

@jml Sorry, no. My project is very small so this is minor for me.

@shepmaster
Copy link
Member

Following the threads further, @jml's solution was to use a partial cache of the relevant pieces:

# We want to save the whole of /cargo between runs, but if we do that by
# sharing a mountpoint with the local filesystem, we hit a bug in libgit2 vs
# vboxsf:
#
# - https://github.com/rust-lang/cargo/issues/2808
# - https://github.com/libgit2/libgit2/issues/3845
#
# Instead, share the registry/cache, which is where most of the data is.

docker run ... -v $(REGISTRY_CACHE):/cargo/registry/cache ...

@omarabid
Copy link

@shepmaster I'm not getting any speed improvements using it. The cache folder is also empty. Mind that I only have one dependency which is "Rand" so I wonder if the cache is used for other stuff?

@jml
Copy link

jml commented Jul 21, 2017

Sorry haven't had a chance to look into this in a while and don't expect to any time soon. I've lost all mental context.

@carols10cents
Copy link
Member

It sounds like there are either workarounds or upstream issues for this, so I'm going to close. Please reopen if I'm incorrect and there's something cargo should be doing here!

jjyr added a commit to jjyr/capsule that referenced this issue Jun 17, 2020
@jjyr
Copy link

jjyr commented Jun 17, 2020

Just have met the same bug in WSL ubuntu-20.

A hint for who has the same issue:

Using local docker volume to map .cargo won't trigger this.

docker run ... -v cargo-cache:/root/.cargo

The .cargo will be cached between different containers as expected.

JonasAlfredsson added a commit to JonasAlfredsson/docker-nginx-certbot that referenced this issue Dec 13, 2021
Some strange issue make so that this arch fails to build on Alpine.
To not hinder the 3.0.0 release we drop this arch, and hopefully
we can reintroduce it in the future.

More info here: pyca/cryptography#6673
and here: rust-lang/cargo#2808
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
@magicse
Copy link

magicse commented Feb 25, 2023

Out of Memory error when building orjson wheel for armv7 Docker on Ubuntu64.
I'm trying to compile Docker image on Ubuntu64 for Home Assistant, but it always fails with an Out of Memory error and failed to fetch https://github.com/rust-lang/crates.io-index when it tries to build the armv7 version.
ijl/orjson#358

#0 24.80   Downloading orjson-3.8.6.tar.gz (655 kB)                                                                                                                                    
#0 25.86      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 655.1/655.1 kB 902.5 kB/s eta 0:00:00                                                                                              
#0 29.00   Installing build dependencies: started                                                                                                                                      
#0 73.69   Installing build dependencies: finished with status 'done'
#0 73.81   Getting requirements to build wheel: started
#0 76.44   Getting requirements to build wheel: finished with status 'done'
#0 76.50   Preparing metadata (pyproject.toml): started
#0 596.0   Preparing metadata (pyproject.toml): still running...
#0 1078.8   Preparing metadata (pyproject.toml): still running...
#0 1527.7   Preparing metadata (pyproject.toml): still running...
#0 1528.0   Preparing metadata (pyproject.toml): finished with status 'error'
#0 1528.3   error: subprocess-exited-with-error
#0 1528.3   
#0 1528.3   × Preparing metadata (pyproject.toml) did not run successfully.
#0 1528.3   │ exit code: 1
#0 1528.3   ╰─> [16 lines of output]
#0 1528.3           Updating crates.io index
#0 1528.3       warning: spurious network error (2 tries remaining): failed to mmap. Could not write data: Out of memory; class=Os (2)
#0 1528.3       warning: spurious network error (1 tries remaining): failed to mmap. Could not write data: Out of memory; class=Os (2)
#0 1528.3       error: failed to get `ahash` as a dependency of package `orjson v3.8.6 (/tmp/pip-install-d1umdm0e/orjson)`
#0 1528.3       
#0 1528.3       Caused by:
#0 1528.3         failed to fetch `https://github.com/rust-lang/crates.io-index`
#0 1528.3       
#0 1528.3       Caused by:
#0 1528.3         failed to mmap. Could not write data: Out of memory; class=Os (2)
#0 1528.3       💥 maturin failed
#0 1528.3         Caused by: Cargo metadata failed. Does your crate compile with `cargo build`?
#0 1528.3         Caused by: `cargo metadata` exited with an error:
#0 1528.3       Error running maturin: Command '['maturin', 'pep517', 'write-dist-info', '--metadata-directory', '/tmp/pip-modern-metadata-6jp59nkn', '--interpreter', '/usr/bin/python3']' returned non-zero exit status 1.
#0 1528.3       Checking for Rust toolchain....
#0 1528.3       Running `maturin pep517 write-dist-info --metadata-directory /tmp/pip-modern-metadata-6jp59nkn --interpreter /usr/bin/python3`
#0 1528.3       [end of output]
#0 1528.3   
#0 1528.3   note: This error originates from a subprocess, and is likely not a problem with pip.
#0 1528.4 error: metadata-generation-failed
#0 1528.4 
#0 1528.4 × Encountered error while generating package metadata.
#0 1528.4 ╰─> orjson
#0 1528.4 
#0 1528.4 note: This is an issue with the package mentioned above, not pip.
#0 1528.4 hint: See above for details.

@williamdes
Copy link

williamdes commented Feb 25, 2023

You should try the workaround I used on my docker image for armv6/armv7
See: #6513 (comment)

ENV CARGO_NET_GIT_FETCH_WITH_CLI=true

Please let us know if works for you

@magicse
Copy link

magicse commented Feb 25, 2023

Hi @williamdes thank you. Yes this works ))

@gl-yziquel
Copy link

I'd say MAP_SHARED instead of MAP_PRIVATE is a possible if not likely culprit, here.

See: rust-lang/rust#122262

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests