[Bug]: Cross-cache deadlock when concurrent updates notify subscribers that modify other SourceCache instances
维护者通常 1 天内回复
@dwcullop 已经在做这个了。
开始于 2026年4月6日。
评估
这个 Issue 还没有评估数据。
描述
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
- 主要语言
- C#
- 星标
- 1.9k
- 派生
- 194
- 平均合并
- 12 分钟
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
reactivemarbles/DynamicData 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
reactivemarbles/DynamicData#1229 ·
维护者通常 1 天内回复
-
infrastructure
难度 2/5 1-3 小时 新手友好度 64/100
reactivemarbles/DynamicData#1089 · 1 条评论 ·
维护者通常 1 天内回复
-
[Bug]: ChangeAwareList merges an insert one slot before a pending AddRange, corrupting list order downstream可能已有人在做 @dwcullop 于 9 天前认领。 未关闭bug
难度 3/5 半天 新手友好度 63/100
reactivemarbles/DynamicData#1225 ·
维护者通常 1 天内回复
-
[Feature]: Make Avg, StdDev, Maximum and Minimum refresh-aware, consistent with Sum可能已有人在做 @dwcullop 于 14 天前认领。 未关闭breaking change enhancement
难度 5/5 一周以上 新手友好度 20/100
reactivemarbles/DynamicData#1214 ·
维护者通常 1 天内回复
-
bug
难度 5/5 一周以上 新手友好度 35/100
reactivemarbles/DynamicData#1196 ·
维护者通常 1 天内回复
查看 reactivemarbles/DynamicData 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
immichFrame/ImmichFrame#735 ·
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
dimitar-radenkov/Pointframe#318 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
DotHarness/dotcraft#546 ·
维护者通常 1 天内回复
-
a-corriger bug
难度 2/5 1-3 小时 新手友好度 78/100
christian-raj/S-Aloha#303 · 1 条评论 ·
-
Input editor says "Apply Changes" even when no changes have been made.可能已有人在做 @hcooper 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 72/100
MobiFlight/MobiFlight-Connector#3526 ·
维护者通常 1 天内回复