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

memmap2 write_all call panics on cacache 10 #32

Closed
chrisdickinson opened this issue Feb 25, 2022 · 4 comments · Fixed by #33
Closed

memmap2 write_all call panics on cacache 10 #32

chrisdickinson opened this issue Feb 25, 2022 · 4 comments · Fixed by #33
Labels
bug Something isn't working

Comments

@chrisdickinson
Copy link

This appears to happen with any vec <= the memmap size.

thread 'main' panicked at 'source slice length (705) does not match destination slice length (0)', /Users/chris/.cargo/registry/src/github.com-1ecc6299db9ec823/cacache-10.0.0/src/content/write.rs:78:18

That backtrace points at:

impl Write for Writer {
    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
        self.builder.input(buf);
        if let Some(mmap) = &mut self.mmap {
            mmap.copy_from_slice(buf); // <-------------------------- this line
            Ok(buf.len())
        } else {
            self.tmpfile.write(buf)
        }
    }

    fn flush(&mut self) -> std::io::Result<()> {
        self.tmpfile.flush()
    }
}

I tested manually lowering the max memmap limit to 0 and it started working again; also pinning cacache at v9 seems to pass as well. I noticed this with both sync and async calls of cacache::write_hash.

My machine is:

  • OS: macOS 12.2.1
  • CPU: (10) arm64 Apple M1 Max
  • Memory: 25.82 GB / 64.00 GB
  • Shell: 3.2.57 - /bin/bash

If there's any other info I can post here to help please let me know, & thanks for cacache!

@zkat
Copy link
Owner

zkat commented Feb 25, 2022

#31 there's a PR for this, but it seems to be a bug in memmap2 itself, so I've been hesitant to merge that PR. I thought the author had sent a bug report over to memmap2 but I guess that didn't happen. I'll go file that issue.

In the meantime, you can safely downgrade to cacache@9.0. The only thing that's changed since then is the bump to memmap2, which is what caused this crash.

@zkat
Copy link
Owner

zkat commented Feb 25, 2022

^ and there's the memmap2 bug

@zkat zkat added the bug Something isn't working label Feb 25, 2022
zkat added a commit that referenced this issue Feb 25, 2022
zkat added a commit that referenced this issue Feb 25, 2022
zkat added a commit that referenced this issue Feb 25, 2022
zkat added a commit that referenced this issue Feb 25, 2022
@zkat zkat closed this as completed in #33 Feb 25, 2022
zkat added a commit that referenced this issue Feb 25, 2022
@zkat
Copy link
Owner

zkat commented Feb 25, 2022

Fixed in 10.0.1

@tgnottingham
Copy link

tgnottingham commented Aug 16, 2022

I'm still seeing this issue with inputs <= 1MiB.

That is, this works:

let _ = cacache::write_hash("./cache", &[b'a'; 1024 * 1024 + 1]).await;

But this results in a panic:

let _ = cacache::write_hash("./cache", &[b'a'; 1024 * 1024]).await;
thread 'blocking-1' panicked at 'source slice length (1048576) does not match destination slice length (0)', /home/tgnottingham/.cargo/registry/src/github.com-1ecc6299db9ec823/cacache-10.0.1/src/content/write.rs:260:38
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'async-std/runtime' panicked at 'task has failed', /home/tgnottingham/.cargo/registry/src/github.com-1ecc6299db9ec823/async-task-4.3.0/src/task.rs:426:45
thread 'main' panicked at 'task has failed', /home/tgnottingham/.cargo/registry/src/github.com-1ecc6299db9ec823/async-task-4.3.0/src/task.rs:426:45

The issue doesn't occur when using cacache::write.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants