[Bug]: Cross-cache deadlock when concurrent updates notify subscribers that modify other SourceCache instances
Maintainer thường phản hồi trong vòng 1 ngày
@dwcullop đang làm issue này rồi.
Từ ngày 6/4/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Describe the bug 🐞
ObservableCache holds its internal _locker during InvokeNext, which calls _changes.OnNext synchronously while the lock is held. When a subscriber modifies a different SourceCache from inside the OnNext callback, that second cache acquires its own _locker and also calls InvokeNext under its lock. If two threads concurrently update two caches that notify into each other, the lock acquisition order inverts between threads, causing a deadlock.
This affects any scenario where SourceCache instances are wired together via Connect subscribers — including PopulateInto, MergeManyChangeSets, or any custom subscriber that writes to another cache in response to changes.
The deadlock is difficult to trigger because it requires concurrent updates to two interdependent caches with subscriber chains that cross cache boundaries.
Reproduction Test
const int iterations = 100;
for (var iter = 0; iter < iterations; iter++)
{
using var cacheA = new SourceCache<TestItem, string>(static x => x.Key);
using var cacheB = new SourceCache<TestItem, string>(static x => x.Key);
using var subA = cacheA.Connect().Subscribe(changes =>
{
foreach (var c in changes)
{
if (c.Reason == ChangeReason.Add && !c.Current.Key.StartsWith("x"))
{
cacheB.AddOrUpdate(new TestItem("x" + c.Current.Key, c.Current.Value));
}
}
});
using var subB = cacheB.Connect().Subscribe(changes =>
{
foreach (var c in changes)
{
if (c.Reason == ChangeReason.Add && !c.Current.Key.StartsWith("x"))
{
cacheA.AddOrUpdate(new TestItem("x" + c.Current.Key, c.Current.Value));
}
}
});
var barrier = new Barrier(2);
var taskA = Task.Run(() =>
{
barrier.SignalAndWait();
for (var i = 0; i < 1000; i++)
{
cacheA.AddOrUpdate(new TestItem("a" + i, "V" + i));
}
});
var taskB = Task.Run(() =>
{
barrier.SignalAndWait();
for (var i = 0; i < 1000; i++)
{
cacheB.AddOrUpdate(new TestItem("b" + i, "V" + i));
}
});
var completed = Task.WhenAll(taskA, taskB);
var finished = await Task.WhenAny(completed, Task.Delay(TimeSpan.FromSeconds(5)));
}
private sealed record TestItem(string Key, string Value);
This test deadlocks on the current main branch.
Reproduction repository
https://gist.github.com/dwcullop/fe877f72ac7d8df4265c8affd771453d
Expected behavior
The deadlock shouldn't happen.
DynamicData Version
DynamicData 9.4.3
- Ngôn ngữ chính
- C#
- Star
- 1.9k
- Fork
- 194
- Merge trung bình
- 12 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của reactivemarbles/DynamicData
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
reactivemarbles/DynamicData#1229 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
infrastructure
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
reactivemarbles/DynamicData#1089 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: ChangeAwareList merges an insert one slot before a pending AddRange, corrupting list order downstreamCó thể đã có người làm @dwcullop đã nhận 9 ngày trước. Đang mởbug
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 63/100
reactivemarbles/DynamicData#1225 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Feature]: Make Avg, StdDev, Maximum and Minimum refresh-aware, consistent with SumCó thể đã có người làm @dwcullop đã nhận 14 ngày trước. Đang mởbreaking change enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
reactivemarbles/DynamicData#1214 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
reactivemarbles/DynamicData#1196 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của reactivemarbles/DynamicData
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
immichFrame/ImmichFrame#735 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
dimitar-radenkov/Pointframe#318 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
DotHarness/dotcraft#546 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
a-corriger bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
christian-raj/S-Aloha#303 · 1 bình luận ·
-
Input editor says "Apply Changes" even when no changes have been made.Có thể đã có người làm @hcooper đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
MobiFlight/MobiFlight-Connector#3526 ·
Maintainer thường phản hồi trong vòng 1 ngày