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

cargo clean doesn't work well from Windows #12214

Closed
emptyfist opened this issue Jun 1, 2023 · 8 comments
Closed

cargo clean doesn't work well from Windows #12214

emptyfist opened this issue Jun 1, 2023 · 8 comments
Labels
C-bug Category: bug S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.

Comments

@emptyfist
Copy link

Problem

I tried to build rust project with Cargo but faced Blocking waiting for xxxxx.
So I tried to clean cargo cache as following
cargo clean

But caches are not cleared from Windows OS so I manually remove those files from System drive.

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version

No response

@emptyfist emptyfist added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Jun 1, 2023
@weihanglo
Copy link
Member

Due to the lack of a minimal set of steps to reproduce, it's hard to help with this issue. Could you add a minimal reproducer and attach the version information via cargo -vV as well?

Besides, a related pull request just got merged #11442. The fix should be released in the next few days on nightly channel.

@weihanglo weihanglo added S-needs-rfc Status: Needs an RFC to make progress. S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. and removed S-triage Status: This issue is waiting on initial triage. S-needs-rfc Status: Needs an RFC to make progress. labels Jun 1, 2023
@emptyfist
Copy link
Author

Sorry for lack information.

cargo 1.69.0 (6e9a833 2023-04-12)
release: 1.69.0
commit-hash: 6e9a833
commit-date: 2023-04-12
host: x86_64-pc-windows-msvc
libgit2: 1.5.0 (sys:0.16.0 vendored)
libcurl: 7.86.0-DEV (sys:0.4.59+curl-7.86.0 vendored ssl:Schannel)
os: Windows 10.0.19044 (Windows 10 Pro N) [64-bit]

@weihanglo
Copy link
Member

What did you want to achieve, what have you done, and what did it exactly mean by “caches are not cleared”?

We need a clear description and a reproducer of the problem to proceed. Thank you.

@emptyfist
Copy link
Author

Sorry for bothering you.

After the cargo project creation, I wrote down some dependencies on cargo.toml.
Started building the project with cargo run and suddenly stopped run command while the crates.index was updating.
After than, built the project with cargo run but Blocking waiting for xxxx was displayed.
So I used cargo clean command to clear the cache several times but same issue happend while build the project.

After remove the registry and cache directory from c:\xxx\.cargo manually, the cargo run worked well.

Please lmk how can I solve the Blocking waiting for xxx error message.

@weihanglo
Copy link
Member

Dud you have any other editor opening the same project? Usually Rust Analyzer or some IDE integration will run cargo check which does block other command from running, as they are downloading and unpacking dependency source code.

If you were stuck in “Blocking waiting for xxxx” for a long while, say 3 minutes, without any IDE integration in the background, it might be a real issue.

If in that case you could try deleting ~/.cargo/registry/.package-cache. That should unlock your registry cache.

@emptyfist
Copy link
Author

Thank you for your advice.
In addition, there are no other editor opening the same project.
Anyway, I manually deleted the above file and after than, it worked well.
Thank you.

@weihanglo
Copy link
Member

weihanglo commented Jun 15, 2023

Cargo uses LockFileEx on Windows to do file locking on .package-cache, if that makes any sense to you.

#[cfg(windows)]
mod sys {
use std::fs::File;
use std::io::{Error, Result};
use std::mem;
use std::os::windows::io::AsRawHandle;
use windows_sys::Win32::Foundation::HANDLE;
use windows_sys::Win32::Foundation::{ERROR_INVALID_FUNCTION, ERROR_LOCK_VIOLATION};
use windows_sys::Win32::Storage::FileSystem::{
LockFileEx, UnlockFile, LOCKFILE_EXCLUSIVE_LOCK, LOCKFILE_FAIL_IMMEDIATELY,
};
pub(super) fn lock_shared(file: &File) -> Result<()> {
lock_file(file, 0)
}
pub(super) fn lock_exclusive(file: &File) -> Result<()> {
lock_file(file, LOCKFILE_EXCLUSIVE_LOCK)
}
pub(super) fn try_lock_shared(file: &File) -> Result<()> {
lock_file(file, LOCKFILE_FAIL_IMMEDIATELY)
}
pub(super) fn try_lock_exclusive(file: &File) -> Result<()> {
lock_file(file, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY)
}
pub(super) fn error_contended(err: &Error) -> bool {
err.raw_os_error()
.map_or(false, |x| x == ERROR_LOCK_VIOLATION as i32)
}
pub(super) fn error_unsupported(err: &Error) -> bool {
err.raw_os_error()
.map_or(false, |x| x == ERROR_INVALID_FUNCTION as i32)
}
pub(super) fn unlock(file: &File) -> Result<()> {
unsafe {
let ret = UnlockFile(file.as_raw_handle() as HANDLE, 0, 0, !0, !0);
if ret == 0 {
Err(Error::last_os_error())
} else {
Ok(())
}
}
}
fn lock_file(file: &File, flags: u32) -> Result<()> {
unsafe {
let mut overlapped = mem::zeroed();
let ret = LockFileEx(
file.as_raw_handle() as HANDLE,
flags,
0,
!0,
!0,
&mut overlapped,
);
if ret == 0 {
Err(Error::last_os_error())
} else {
Ok(())
}
}
}
}

If you can reproduce it very constantly, would you be willing to provide a minimal reproducible example?

@emptyfist
Copy link
Author

Got it.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.
Projects
None yet
Development

No branches or pull requests

2 participants