fix(sync): compare stand-ins again after a proxy download that did not finish
The agent recorded the server's update time for a cache of stand-in thumbnails before the proxy download it queued, so a download that failed (server restart, network drop) was never queued again once its backoff ended: the server's sequence may never change again. A comparison that offers proxies is now recorded only once their download is queued, and dropped when that download ends other than done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
2 files changed
+46
-3
No files matched your search
@@ -237,6 +237,9 @@ public sealed class SyncAgent : IAsyncDisposable
|
||||
var job = await _sync.Database.Jobs.GetAsync(jobId, cancellationToken).ConfigureAwait(false);
|
||||
if (job?.State is JobState.Queued or JobState.Running or JobState.Paused) continue;
|
||||
_proxyJobs.Remove(remoteId);
|
||||
// A download of stand-ins' proxies that did not finish compares the cache with the manifest again (after its
|
||||
// backoff when it failed): the server's sequence may never change again to ask for it.
|
||||
if (job?.State != JobState.Done) _standInsCompared.Remove(remoteId);
|
||||
if (job?.State == JobState.Failed)
|
||||
{
|
||||
var failures = _proxyFailures.GetValueOrDefault(remoteId).Failures + 1;
|
||||
@@ -255,6 +258,8 @@ public sealed class SyncAgent : IAsyncDisposable
|
||||
var job = await _sync.EnqueueDownloadAsync(_engine!, Server, link.RemoteId, link.Title, SyncDownloadMode.Proxies, null, JobPriority.Background,
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
_proxyJobs[link.RemoteId] = job.Id;
|
||||
// Compared at this update time once the download that brings what the server offers is queued.
|
||||
if (!link.ServerHasProxies) _standInsCompared[link.RemoteId] = link.RemoteUpdatedAt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +268,9 @@ public sealed class SyncAgent : IAsyncDisposable
|
||||
/// of a cache that did not record its kind) or that has no cached file. The sequence's proxy flag cannot say: it waits
|
||||
/// for every frame, a missing or damaged one never gets a proxy, and clients and render nodes send the other frames'
|
||||
/// proxies one by one. The manifest is read once per change of the server's sequence, since a proxy that arrives
|
||||
/// leaves a new update time (the proxy pass it queues records the sequence's state).
|
||||
/// leaves a new update time (the proxy pass it queues records the sequence's state). A comparison that offers nothing
|
||||
/// is recorded here; one that offers proxies is recorded when their download is queued, and dropped when that
|
||||
/// download does not finish (<see cref="QueueProxiesAsync"/>).
|
||||
/// </summary>
|
||||
private async Task<bool> OffersProxiesAsync(SyncLink link, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -280,9 +287,10 @@ public sealed class SyncAgent : IAsyncDisposable
|
||||
Log.Info(LogCategory, $"The proxies of {link.Title} on {Server} could not be compared: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
_standInsCompared[link.RemoteId] = link.RemoteUpdatedAt;
|
||||
var cached = _sync.Proxies.Kinds(Server, link.RemoteId);
|
||||
return manifest.Frames.Any(f => f.HasProxy && cached.GetValueOrDefault(f.Id) != ProxyCache.Proxy);
|
||||
if (manifest.Frames.Any(f => f.HasProxy && cached.GetValueOrDefault(f.Id) != ProxyCache.Proxy)) return true;
|
||||
_standInsCompared[link.RemoteId] = link.RemoteUpdatedAt;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Waits for a wake-up or the delay; false when stopping.</summary>
|
||||
|
||||
@@ -192,6 +192,41 @@ public sealed class SyncAgentTests(TestContext context)
|
||||
Assert.Count(2, await DownloadsAsync(f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AStandInDownloadThatFailedIsQueuedAgainAfterItsBackoff()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var remote = f.Remote.Add("Fog", f.NewPhotos(3), status: SequenceStatus.ThumbsBuilt);
|
||||
remote.Undecodable = true;
|
||||
var engine = await f.StartEngineAsync();
|
||||
await f.RefreshAsync();
|
||||
var first = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Fog", SyncDownloadMode.Proxies, null);
|
||||
await f.Archive.WaitForAsync(first.Id, JobState.Done);
|
||||
await using var agent = new SyncAgent(f.Sync, f.Remote, () => new SyncPolicy(KeepProxiesOffline: true), engine, EventsOnly);
|
||||
agent.Start();
|
||||
await WaitAsync(() => agent.Snapshot is not null, "first comparison");
|
||||
|
||||
// Two frames' proxies reach the server, but their download fails (the server restarts meanwhile).
|
||||
foreach (var frame in remote.Frames.Take(2)) f.Remote.SentProxies[frame.Id] = frame.Proxy;
|
||||
remote.UpdatedAt = DateTimeOffset.UtcNow.AddSeconds(1);
|
||||
f.Remote.FailAssets = true;
|
||||
await agent.RefreshAsync(f.Ct);
|
||||
var failed = Assert.Contains(await DownloadsAsync(f), j => j.Id != first.Id);
|
||||
await f.Archive.WaitForAsync(failed.Id, JobState.Failed);
|
||||
|
||||
// The server's sequence does not change again: once the backoff has passed, the download is queued anyway.
|
||||
f.Remote.FailAssets = false;
|
||||
await WaitAsync(async () =>
|
||||
{
|
||||
await agent.RefreshAsync(f.Ct);
|
||||
return (await DownloadsAsync(f)).Count == 3;
|
||||
}, "the download queued again");
|
||||
var retry = Assert.Contains(await DownloadsAsync(f), j => j.Id != first.Id && j.Id != failed.Id);
|
||||
await f.Archive.WaitForAsync(retry.Id, JobState.Done);
|
||||
var opened = Assert.NotNull(f.Sync.OpenRemote(f.Server, remote.Id));
|
||||
Assert.SequenceEqual([remote.Frames[0].Proxy.Length, remote.Frames[1].Proxy.Length, 64], opened.Files.Select(file => (int)new FileInfo(file!).Length));
|
||||
}
|
||||
|
||||
private static async Task<IReadOnlyList<Job>> DownloadsAsync(SyncFixture f) =>
|
||||
(await f.Db.Jobs.ListAsync(null, JobKind.Download, 100, null, f.Ct)).Items;
|
||||
|
||||
|
||||
Reference in new issue
Block a user