Skip to content

Fix deadlock in test_machine_a_tron_rack_integration#3695

Open
kensimon wants to merge 1 commit into
NVIDIA:mainfrom
kensimon:fix-deadlock-force-delete
Open

Fix deadlock in test_machine_a_tron_rack_integration#3695
kensimon wants to merge 1 commit into
NVIDIA:mainfrom
kensimon:fix-deadlock-force-delete

Conversation

@kensimon

Copy link
Copy Markdown
Contributor

A few PR's have had the same deadlock cause issues: Our integration tests run admin_force_delete_machine (just to get some extra coverage on it) after asserting they come up as Ready, and there's occasional issues where site explorer is concurrently hitting the same endpoints at the same time.

If site explorer modifies endpoint A and then endpoint B in the same transaction, but admin_force_delete_machine deletes endpoint B and then endpoint A in its own transaction, we get a deadlock.

Make sure that any transaction that's writing to multiple explored endpoints, does so in sorted order, so that they don't deadlock.

Related issues

Type of Change

  • Add - New feature or capability
  • Change - Changes in existing functionality
  • Fix - Bug fixes
  • Remove - Removed features or deprecated functionality
  • Internal - Internal changes (refactoring, tests, docs, etc.)

Breaking Changes

  • This PR contains breaking changes

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • No testing required (docs, internal refactor, etc.)

Additional Notes

I was able to reproduce the deadlock (cargo test --package carbide-api-integration-tests test_machine_a_tron_rack_integration -- --exact --nocapture) pretty reliably about 50% of the time locally, and after this fix I haven't been able to reproduce it once.

A few PR's have had the same deadlock cause issues: Our integration
tests run admin_force_delete_machine (just to get some extra coverage on
it) after asserting they come up as Ready, and there's occasional issues
where site explorer is concurrently hitting the same endpoints at the
same time.

If site explorer modifies endpoint A and then endpoint B in the same
transaction, but admin_force_delete_machine deletes endpoint B and then
endpoint A in *its* own transaction, we get a deadlock.

Make sure that any transaction that's writing to multiple explored
endpoints, does so in sorted order, so that they don't deadlock.
@kensimon
kensimon requested a review from a team as a code owner July 17, 2026 22:02
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • Bug Fixes
    • Improved machine force-deletion reliability by using consistent endpoint cleanup ordering.
    • Reduced the risk of database deadlocks during concurrent machine exploration and deletion.
    • Ensured boot interface and explored endpoint updates are processed in a consistent address order.
  • Tests
    • Added coverage verifying force deletion completes successfully while exploration updates are in progress.

Walkthrough

The change makes Site Explorer persistence and admin force-delete cleanup process explored endpoint records in deterministic BMC address order. A new SQLx integration test verifies concurrent exploration and force-delete behavior across a managed host and multiple DPUs.

Changes

Explored endpoint lock ordering

Layer / File(s) Summary
Site Explorer write ordering
crates/site-explorer/src/lib.rs
Boot interfaces and exploration results are sorted by endpoint address before database persistence and metric processing.
Force-delete cleanup and concurrency coverage
crates/api-core/src/handlers/machine.rs, crates/api-core/src/tests/machine_admin_force_delete.rs
Force-delete removes explored host and endpoint records in sorted BMC address order, and the integration test verifies completion during concurrent exploration updates.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: fixing a deadlock in the integration test flow.
Description check ✅ Passed The description is directly related to the changes and accurately explains the deadlock and sorted-order fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/api-core/src/tests/machine_admin_force_delete.rs`:
- Around line 427-439: Update the deletion assertions in the force-delete test
after the all_done check to pass each endpoint’s expected address from the
addresses collected during exploration into validate_machine_deletion instead of
None. Keep validating both managed DPU IDs and the host ID, and ensure every
explored endpoint is asserted deleted.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 135305ab-d10a-43fa-9abb-9fe3e2174044

📥 Commits

Reviewing files that changed from the base of the PR and between 0e59cee and 25b6bb4.

📒 Files selected for processing (3)
  • crates/api-core/src/handlers/machine.rs
  • crates/api-core/src/tests/machine_admin_force_delete.rs
  • crates/site-explorer/src/lib.rs

Comment on lines +427 to +439
let response = force_delete_task
.await
.unwrap()
.expect("force delete completes once exploration commits")
.into_inner();
assert!(response.all_done);
for machine_id in managed_host
.dpu_ids
.iter()
.chain(std::iter::once(&managed_host.id))
{
validate_machine_deletion(&env, machine_id, None).await;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert that every explored endpoint was deleted.

Passing None lets this regression test succeed even if cleanup leaves host or DPU endpoint rows behind. Use the addresses already collected by the test.

Proposed fix
-        validate_machine_deletion(&env, machine_id, None).await;
+        validate_machine_deletion(&env, machine_id, Some(&endpoint_addresses)).await;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let response = force_delete_task
.await
.unwrap()
.expect("force delete completes once exploration commits")
.into_inner();
assert!(response.all_done);
for machine_id in managed_host
.dpu_ids
.iter()
.chain(std::iter::once(&managed_host.id))
{
validate_machine_deletion(&env, machine_id, None).await;
}
let response = force_delete_task
.await
.unwrap()
.expect("force delete completes once exploration commits")
.into_inner();
assert!(response.all_done);
for machine_id in managed_host
.dpu_ids
.iter()
.chain(std::iter::once(&managed_host.id))
{
validate_machine_deletion(&env, machine_id, Some(&endpoint_addresses)).await;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/api-core/src/tests/machine_admin_force_delete.rs` around lines 427 -
439, Update the deletion assertions in the force-delete test after the all_done
check to pass each endpoint’s expected address from the addresses collected
during exploration into validate_machine_deletion instead of None. Keep
validating both managed DPU IDs and the host ID, and ensure every explored
endpoint is asserted deleted.

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.

2 participants