Trying to figure out why this code hangs. I can remove any one of the 3 lines at the bottom of the test and it won't hang, but all 3 together makes it hang. Any help would be greatly appreciated!
[Fact]
public async Task CanAddValuesInParallel() {
var muxer = ConnectionMultiplexer.Connect("localhost");
var db = muxer.GetDatabase();
await AddAsync(db, "test", "1");
await db.KeyDeleteAsync("test");
Task.Run(() => AddAsync(db, "test", "1")).Wait();
}
public async Task<bool> AddAsync(IDatabase db, string key, string value) {
return await db.StringSetAsync(key, value, null, When.NotExists);
}
Task.Run
and whyWait()
? – i3arnonTask.Run(() => AddAsync(db, "test", "1")).Wait();
. Here you have deadlock. – Hamlet HakobyanSynchronizationContext
for all its test methods. This can cause a number of problems when mixing synchronous and asynchronous code. I suspect you're seeing some combination of problems I describe in two blog posts here and here. – Stephen Cleary