feat: [#164] implement ReentrantMutex<RefCell<UserOutput>> pattern#166
Merged
Conversation
Replace Arc<Mutex<UserOutput>> with Arc<ReentrantMutex<RefCell<UserOutput>>> throughout codebase to resolve same-thread reentrancy deadlock. Key changes: - Add parking_lot dependency for ReentrantMutex support - Update Container, ExecutionContext, and all controllers - Convert ProgressReporter to use ReentrantMutex pattern - Fix test infrastructure compatibility with parking_lot - Add comprehensive reentrancy verification tests - Update error handling to use ReentrantMutex pattern - Add architectural decision record for pattern choice All core functionality maintained while eliminating deadlock risk. Tests verify same-thread multiple lock acquisitions work correctly.
- Remove unused _user_output variables from all test functions - Remove unused _working_dir parameter from create_test_context function - Remove unused imports (TestUserOutput and std::path::Path) - Simplify test setup by removing unnecessary user output instances
…tests - Add create_test_dependencies() helper function to eliminate code duplication - Remove repeated UserOutput, RepositoryFactory, and SystemClock creation in tests - Improve test maintainability and readability - All 4 test functions now use the centralized helper function - Add comprehensive documentation for the helper function
- Systematic analysis of all test modules in src/presentation/user_output/core.rs - Moved 22 unit tests to appropriate struct modules: - 6 type-safe wrapper tests → sinks/writers.rs - 16 verbosity filter tests → verbosity.rs - Removed 7 duplicate theme tests from core.rs - Preserved 8 integration test modules in core.rs (~65+ tests) - All tests continue to pass, no functionality lost - Clear separation: unit tests (single struct) in modules, integration tests (multiple structs) in core.rs - Reduced core.rs from 2396 to 2282 lines while maintaining comprehensive test coverage
- Move 29 tests from core.rs to appropriate module files: - 3 tests → progress.rs (ProgressMessage tests) - 1 test → success.rs (SuccessMessage tests) - 1 test → error.rs (ErrorMessage tests) - 2 tests → result.rs (ResultMessage tests) - 1 test → warning.rs (WarningMessage tests) - 1 test → channel.rs (Channel enum tests) - 10 tests → steps.rs (StepsMessage tests) - 9 tests → info_block.rs (InfoBlockMessage tests) - 2 tests → composite.rs (CompositeSink tests) - 1 test → telemetry.rs (TelemetrySink tests) - Remove all duplicate tests from core.rs (350+ lines reduction) - Improve test organization by placing tests with their related types - Maintain 100% test coverage with all 137 user_output tests passing - Clean up module structure for better maintainability
Member
Author
|
ACK f071644 |
14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR implements the
ReentrantMutex<RefCell<UserOutput>>pattern to resolve same-thread deadlock issues described in #164. The implementation allows nested calls toUserOutputmethods within the same thread while maintaining thread safety.Problem Statement
The previous
Arc<Mutex<UserOutput>>pattern caused deadlocks when:Solution
Replaced
Arc<Mutex<UserOutput>>withArc<ReentrantMutex<RefCell<UserOutput>>>throughout the codebase:parking_lotcrate)Key Changes
Core Implementation
Arc<Mutex<UserOutput>>→Arc<ReentrantMutex<RefCell<UserOutput>>>.lock().unwrap()→.lock().borrow_mut()for mutable operationsparking_lot = { version = "0.12.3", features = ["std"] }Updated Components
src/bootstrap/container.rs)Testing
tests/user_output_reentrancy.rsTechnical Details
Access Patterns
Type Definitions
Architecture Decision
This change is documented in
docs/decisions/reentrant-mutex-useroutput-pattern.mdwith:Quality Validation
✅ All pre-commit checks passed:
Breaking Changes
❌ None - This is an internal implementation change that maintains all existing public APIs.
Migration Notes
No migration required for users of the application. The change is transparent to:
Future Considerations
Related Issues
Closes #164
Checklist