fix(pm): add thread synchronization to prevent race conditions#197
fix(pm): add thread synchronization to prevent race conditions#197
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes race conditions in package manager operations by adding thread synchronization using mutex locks. The changes prevent "Directory not empty" errors during concurrent execution, particularly in test scenarios.
- Added global mutex lock for critical file system operations in the package manager
- Protected directory removal, renaming, and shim file creation operations
- Added test-specific synchronization for temporary directory creation
Comments suppressed due to low confidence (1)
crates/vite_package_manager/src/package_manager.rs:1
- The lock scope is too broad and includes potentially long-running operations like
create_shim_files. Consider reducing the lock scope to only protect the critical directory operations (remove and rename) to avoid blocking other threads unnecessarily during shim file creation.
use std::{
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
6e1ad6d to
4d1b317
Compare
…itions - Add global mutex lock using OnceLock for file system operations - Protect critical sections in download_package_manager function - Add test-specific lock for temp directory creation - Fix "Directory not empty" errors during concurrent test execution The synchronization ensures concurrent calls won't interfere when: - Checking if files exist - Removing old directories - Renaming temporary directories - Creating shim files 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
4d1b317 to
53a92fb
Compare
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
crates/vite_package_manager/src/package_manager.rs:1
- The mutex lock is held during the entire file system operation sequence, including potentially slow operations like
remove_dir_all_force,tokio::fs::rename, andcreate_shim_files. This could create a bottleneck if multiple package managers need to be downloaded concurrently. Consider using a more granular locking strategy or per-directory locks instead of a global lock.
use std::{
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
This issue only exists when single testing is performed in a multi-threaded concurrent execution environment; it does not occur in actual user operations. Before performing any repairs, it is necessary to have these tests executed in the correct order. |

closes #140
The synchronization ensures concurrent calls won't interfere when:
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com