fix concurrency: resolve deadlock and lock ordering in P2P shutdown and
peer mapping
This commit is contained in:
@@ -484,11 +484,14 @@ pub fn shutdownImpl(p2p: *P2P) void {
|
||||
p2p.state_mutex.unlock();
|
||||
|
||||
// Clear event queue
|
||||
p2p.event_mutex.lock();
|
||||
defer p2p.event_mutex.unlock();
|
||||
p2p.event_queue.clearRetainingCapacity();
|
||||
{
|
||||
p2p.event_mutex.lock();
|
||||
defer p2p.event_mutex.unlock();
|
||||
p2p.event_queue.clearRetainingCapacity();
|
||||
}
|
||||
|
||||
// Emit final event (ignore errors during shutdown)
|
||||
// Must be outside event_mutex scope — emitEvent takes the lock internally
|
||||
p2p.emitEvent(P2PEvent.create(.library_stopped, .library_stopped)) catch |err| {
|
||||
std.log.warn("Failed to emit shutdown event: {}", .{err});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user