Cette page n'est pas encore traduite. La version anglaise est affichée ci-dessous.
FDB0003: Watch awaited inside the handler that created it
| Analyzer | FoundationDB.Client |
| Severity | Error |
| Code fix | No |
Message
A watch fires only after its transaction commits, and this await blocks the commit. Return the FdbWatch from the handler and await it after WriteAsync returns.
Why
A watch is registered at commit time, and fires only when the key changes after that commit. An await on the watch inside the handler waits for a commit that cannot happen until the handler returns. The transaction expires after five seconds with transaction_too_old, and the retry loop runs the handler again, forever. The rule reports await watch and await watch.WaitAsync(...) inside a ReadAsync, WriteAsync, or ReadWriteAsync handler.
Bad
await db.WriteAsync(async tr =>
{
var watch = tr.Watch(key, ct);
await watch;
}, ct);
Good
FdbWatch watch = await db.ReadWriteAsync(tr => Task.FromResult(tr.Watch(key, ct)), ct);
await watch;
The handler returns the watch, and the caller awaits it once the transaction has committed.
Suppress
#pragma warning disable FDB0003 // reason
or, for a whole project, in .editorconfig:
dotnet_diagnostic.FDB0003.severity = none