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

PermissionDenied, message: "Access is denied." at remove file after read on Github Action WIndows #108

Open
LokiSharp opened this issue Dec 15, 2023 · 2 comments

Comments

@LokiSharp
Copy link

I'm trying to test a rust project on Github Action but it yields an error only on Windows.

That's all right at my desktop and Github Action Linux/macos so I don't know what I should troubleshoot.

    #[test]
    fn file_remove() {
        let tempdir = tempfile::tempdir().unwrap();
        let path = tempdir.path().join("mmap");

        let mut file = OpenOptions::new()
            .read(true)
            .write(true)
            .create(true)
            .open(path.clone())
            .unwrap();
        file.set_len(128).unwrap();

        let mmap = unsafe { Mmap::map(&file) };

        assert!(mmap.is_ok());

        let remove_res = fs::remove_file(path.clone());
        if remove_res.is_err() {
            println!("remove_res: {:?}", remove_res);
        }
        assert!(remove_res.is_ok());
    }

https://github.com/LokiSharp/memmap2-rs/blob/00de205e006aabb69e03172c04da869c18cd776f/src/lib.rs#L1575

---- test::file_remove stdout ----
remove_res: Err(Os { code: 5, kind: PermissionDenied, message: "Access is denied." })
thread 'test::file_remove' panicked at src\lib.rs:1595:9:
assertion failed: remove_res.is_ok()
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

https://github.com/LokiSharp/memmap2-rs/actions/runs/7223354238/job/19682434953

@adamreichold
Copy link

Isn't that how Windows generally behaves, i.e. that opened files cannot be deleted? (I think it is more forgiving w.r.t. to the mappings.) So I think you want to call drop(file); before calling remove_file in your test? Possibly even drop(mmap); but I am not sure about the second one.

@LokiSharp
Copy link
Author

Theoretically, that's the case, but what confuses me is that on my local Windows 11 machine, I can delete the file normally without needing to drop mmap. However, only on Github Action's Windows Server 2022 does it throw an error. I will try to set up Windows Server 2022 locally for testing. I suspect that the difference in how Windows Server 2022 and Windows 11 handle memory mapping might be the cause.

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

2 participants