mosec icon indicating copy to clipboard operation
mosec copied to clipboard

feat: add loom concurrency testing with conditional sync primitives

Open Copilot opened this issue 8 months ago • 0 comments

This PR adds loom testing to detect concurrency bugs like deadlocks and data races in the Rust codebase. The implementation uses a conditional sync primitives approach to enable loom testing without affecting normal builds.

Background

The implementation addresses deadlock bugs that occurred in:

  • #316: deadlock in nested function calls with multiple locks
  • #311: deadlock when lots of client requests closed before response

Implementation

Conditional Sync Primitives: Created a sync.rs module that conditionally exports either std::sync or loom::sync primitives based on feature flags. This allows the same TaskManager code to be tested under loom's concurrency model.

Targeted Testing: The loom tests reproduce the exact mutex locking patterns from TaskManager methods like notify_task_done and delete_task that caused the reported deadlocks.

Usage

# Run loom tests
make test_loom
# or directly:
cargo test --features loom_tests loom_

Tests Added

  1. loom_concurrent_notify_delete: Tests the concurrent execution of notify_task_done and delete_task operations that mirror the problematic patterns from issues #311 and #316

  2. loom_concurrent_table_access: Tests different mutex acquisition orders (table→notifiers vs notifiers→table) that can cause deadlocks

The tests successfully model the synchronization behavior and can detect the types of concurrency issues that occurred in production.

Fixes #317.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot avatar Jul 11 '25 03:07 Copilot