refactor: flush storage when compiler close#13395
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors persistent-cache storage writes to be queued asynchronously and introduces an explicit flush-on-close path so pending writes complete when the compiler shuts down.
Changes:
- Update JS compiler shutdown to await the native
close()promise when present. - Refactor
rspack_storage::Storagefrom a oneshot-based “trigger_save” API tosave()+flush(), and wireCache::close()to flush pending writes. - Make filesystem transaction file moves tolerant of missing source files (with a new test).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/rspack/src/Compiler.ts | Await native compiler close promise during shutdown. |
| packages/rspack-test-tools/src/case/cache.ts | Remove explicit mode: 'production' from cache test options. |
| crates/rspack_storage/src/lib.rs | Change storage trait to async save() + flush() API. |
| crates/rspack_storage/src/memory/mod.rs | Implement no-op save()/flush() for in-memory storage. |
| crates/rspack_storage/src/filesystem/mod.rs | Implement new storage API; enqueue DB writes and add flush(). |
| crates/rspack_storage/src/filesystem/db/mod.rs | Change DB save to enqueue-only and print on failures. |
| crates/rspack_storage/src/filesystem/scope_fs.rs | Ignore NotFound on rename during move; add test case. |
| crates/rspack_storage/src/error.rs | Adjust “not found” string matching heuristic. |
| crates/rspack_core/src/cache/mod.rs | Add Cache::close() hook. |
| crates/rspack_core/src/cache/persistent/mod.rs | Use new storage save() API and flush on cache close. |
| crates/rspack_core/src/cache/mixed.rs | Delegate close() to the persistent cache. |
| crates/rspack_core/src/compiler/mod.rs | Call cache.close().await during compiler close. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
🎉 Size decreased by 9.50KB from 48.66MB to 48.65MB (⬇️0.02%) |
Merging this PR will not alter performance
Comparing Footnotes
|
ce5da4a to
49e2c36
Compare
49e2c36 to
125f350
Compare
Summary
fn trigger_save() -> Result<Receiver>tofn save() -> Result<()>, and provide aflushmethod to ensure the write operation is complete.trait Storage { ... - fn trigger_save(&self) -> Result<Receiver<Result<()>>>; + async fn save(&self) -> Result<()>; + async fn flush(&self); }class Compiler { close(callback: (error?: Error | null) => void) { ... - this.#instance?.close(); - callback(); + const closePromise = this.#instance?.close(); + if (closePromise) { + closePromise.then(() => callback(), callback); + } else { + callback(); + } ... } }Related links
Checklist