public async Task UpdateSessionAsync(Session session, DateTime leaseEnd, CancellationToken cancellation) { if (session == default) { throw new ArgumentDefaultException(nameof(session)); } IStoredSession current = await _storage.GetSessionAsync(session, cancellation), start, desired; do { start = current; if (start == null || _storedSessionManager.IsEnded(start)) { throw new SessionTerminatedException(session); } desired = _storedSessionManager.UpdateLease(start, leaseEnd); current = await _storage.UpdateSessionAsync(desired, start, cancellation); }while (start != current); }