Skip to content

Conversation

Copy link

Copilot AI commented Jul 11, 2025

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:

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 fix: resolve deadlock when lots of client requests closed before response #311 and fix: hold one lock at a time to avoid the deadlock in nested function #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 AI and others added 2 commits July 11, 2025 03:21
Co-authored-by: kemingy <12974685+kemingy@users.noreply.github.com>
Co-authored-by: kemingy <12974685+kemingy@users.noreply.github.com>
Copilot AI changed the title [WIP] feat: add loom test feat: add loom test for concurrent Rust code Jul 11, 2025
Copilot AI requested a review from kemingy July 11, 2025 03:23
Copilot finished work on behalf of kemingy July 11, 2025 03:23
Copy link
Member

@kemingy kemingy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the loom to a dev target.

Co-authored-by: kemingy <12974685+kemingy@users.noreply.github.com>
Copilot AI requested a review from kemingy July 11, 2025 03:45
Copilot finished work on behalf of kemingy July 11, 2025 03:45
…ature

Co-authored-by: kemingy <12974685+kemingy@users.noreply.github.com>
Copilot finished work on behalf of kemingy July 11, 2025 07:01
Co-authored-by: kemingy <12974685+kemingy@users.noreply.github.com>
Copilot AI requested a review from kemingy July 29, 2025 11:00
Copilot finished work on behalf of kemingy July 29, 2025 11:00
Cargo.toml Outdated
Comment on lines 63 to 68
[features]
loom = ["dep:loom"]

[dependencies.loom]
version = "0.7"
optional = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add loom to dev-dependencies.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved loom to dev-dependencies and switched to a feature-based approach instead of RUSTFLAGS to avoid dependency conflicts. The tests now work correctly with cargo test --features loom_tests loom_ (commit 703234d).

Makefile Outdated

test_loom:
echo "Running loom tests for concurrency validation"
cargo test --features loom loom_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use RUSTFLAGS="--cfg loom"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use feature flags instead of RUSTFLAGS. Using --cfg loom globally caused compilation issues with dependencies like concurrent-queue. The new approach uses cargo test --features loom_tests loom_ which works correctly (commit 703234d).

src/tasks.rs Outdated
#[test]
fn loom_concurrent_notify_delete() {
loom::model(|| {
let task_manager = TaskManager::new(1000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should create a sync.rs file that contains both std and loom sync to be imported by TaskManager to use. Otherwise, this test doesn't add any benefit from loom.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created sync.rs module with conditional compilation for std vs loom sync primitives. TaskManager now uses these conditional sync primitives, and the loom tests can properly model the synchronization behavior to detect concurrency issues (commit 703234d).

Copilot AI and others added 2 commits July 30, 2025 08:41
…alidation

Co-authored-by: kemingy <12974685+kemingy@users.noreply.github.com>
…om tests

Co-authored-by: kemingy <12974685+kemingy@users.noreply.github.com>
Copilot AI changed the title feat: add loom test for concurrent Rust code feat: add loom concurrency testing with conditional sync primitives Jul 30, 2025
Copilot finished work on behalf of kemingy July 30, 2025 08:50
Copilot AI requested a review from kemingy July 30, 2025 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add loom test

2 participants