Skip to content

Commit 4cf6044

Browse files
0.4.2
1 parent c2fda7d commit 4cf6044

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/storage/dig_archive.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ impl DigArchive {
218218
file.sync_all()?;
219219
drop(file);
220220

221+
// On Windows, add a small delay to ensure file handle is fully released
222+
// before attempting to memory-map the file
223+
#[cfg(windows)]
224+
std::thread::sleep(std::time::Duration::from_millis(100));
225+
221226
let mut archive = Self {
222227
archive_path,
223228
header,
@@ -226,7 +231,30 @@ impl DigArchive {
226231
dirty: false,
227232
};
228233

234+
// Retry memory mapping with backoff on Windows
235+
#[cfg(windows)]
236+
{
237+
let mut attempts = 0;
238+
const MAX_ATTEMPTS: usize = 5;
239+
240+
loop {
241+
match archive.load_mmap() {
242+
Ok(()) => break,
243+
Err(e) if attempts < MAX_ATTEMPTS => {
244+
attempts += 1;
245+
// Exponential backoff: 50ms, 100ms, 200ms, 400ms, 800ms
246+
let delay = 50 * (1 << attempts);
247+
std::thread::sleep(std::time::Duration::from_millis(delay));
248+
continue;
249+
}
250+
Err(e) => return Err(e),
251+
}
252+
}
253+
}
254+
255+
#[cfg(not(windows))]
229256
archive.load_mmap()?;
257+
230258
Ok(archive)
231259
}
232260

src/storage/store.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,19 @@ impl Store {
9393
}
9494
}
9595

96-
// Longer delay to ensure all file handles are released on Windows
97-
std::thread::sleep(std::time::Duration::from_millis(500));
98-
99-
// Try to force garbage collection
100-
std::hint::black_box(());
96+
// On Windows, use longer delay and force garbage collection
97+
#[cfg(windows)]
98+
{
99+
std::thread::sleep(std::time::Duration::from_millis(500));
100+
// Force garbage collection multiple times to ensure cleanup
101+
for _ in 0..3 {
102+
std::hint::black_box(());
103+
std::thread::sleep(std::time::Duration::from_millis(50));
104+
}
105+
}
106+
107+
#[cfg(not(windows))]
108+
std::thread::sleep(std::time::Duration::from_millis(100));
101109

102110
// Remove existing .digstore file to proceed with new initialization
103111
std::fs::remove_file(&digstore_path)?;

0 commit comments

Comments
 (0)