Skip to content

Commit 6a34c2a

Browse files
wjlafranceclaude
andcommitted
Fix Friend.Sync deadlock via consistent lock ordering
Friend.Sync() locked source then target. If two users interacted simultaneously with swapped source/target, ABBA deadlock occurred. Fix by always locking the object with the lower identity hash first. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b0635c9 commit 6a34c2a

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/Atlasd/Battlenet/Friend.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,20 @@ public void Sync(GameState source)
6060
return;
6161
}
6262

63-
lock (source)
63+
// Enforce consistent lock ordering to prevent ABBA deadlock.
64+
// Always lock the object with the lower RuntimeHelpers hash first.
65+
var first = source;
66+
var second = target;
67+
if (System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(source) >
68+
System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(target))
6469
{
65-
lock (target)
70+
first = target;
71+
second = source;
72+
}
73+
74+
lock (first)
75+
{
76+
lock (second)
6677
{
6778
var admin = source.HasAdmin();
6879
var mutual = false;

0 commit comments

Comments
 (0)