fix concurrency: resolve deadlock and lock ordering in P2P shutdown and

peer mapping
This commit is contained in:
2026-02-11 14:19:09 -03:00
parent 4c64c4cc0a
commit 88a2abe521
3 changed files with 55 additions and 21 deletions

View File

@@ -372,9 +372,27 @@ test "lifecycle: error state and recovery" {
// This is expected behavior - recovery resets to clean state
}
// Note: shutdown test disabled due to deadlock in event emission during shutdown
// This is a known limitation - shutdown should be called only when not holding locks
// test "lifecycle: shutdown force terminates" { ... }
test "lifecycle: shutdown completes cleanly" {
const allocator = testing.allocator;
var instance = try P2P.init(allocator, createTestConfig());
defer instance.deinit();
try instance.start();
// Process a few update cycles to let the system settle
var i: usize = 0;
while (i < 5) : (i += 1) {
try instance.update();
std.Thread.sleep(10 * std.time.ns_per_ms);
}
// Shutdown should complete without deadlock (H2 fix: event_mutex scoped in shutdownImpl)
try instance.stop();
// Verify state is stopped
try testing.expectEqual(P2PState.Initialized, instance.getState());
}
// ============================================================================
// TIER 1: Event System