fix(render-node): a dropped proxy download starts over instead of resuming
Originals are resumed from their partial file because their SHA-256 checks the result. Proxies have no hash on the server and can be rebuilt between two attempts, so appending to what a dropped attempt left could mix two versions; a retry now fetches the proxy whole. 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
+42
-13
No files matched your search
@@ -308,8 +308,9 @@ public sealed class RenderNodeClient : IAsyncDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A proxy into the job folder (regenerable, so neither cached nor hashed: the server keeps no hash of it); the original
|
||||
/// when the server has none for the frame.
|
||||
/// A proxy into the job folder (regenerable, so neither cached nor hashed: the server keeps no hash of it, and a retry
|
||||
/// fetches it whole, since a proxy rebuilt meanwhile must not be resumed from the old one); the original when the server
|
||||
/// has none for the frame.
|
||||
/// </summary>
|
||||
private async Task<string> DownloadProxyAsync(ManifestFrame frame, string work, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -317,7 +318,7 @@ public sealed class RenderNodeClient : IAsyncDisposable
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
try
|
||||
{
|
||||
await FetchAsync(frame, "proxy", path, cancellationToken).ConfigureAwait(false);
|
||||
await FetchAsync(frame, "proxy", path, resume: false, cancellationToken).ConfigureAwait(false);
|
||||
return path;
|
||||
}
|
||||
catch (TitanoApiException ex) when (ex.Status == HttpStatusCode.NotFound)
|
||||
@@ -343,7 +344,7 @@ public sealed class RenderNodeClient : IAsyncDisposable
|
||||
for (var attempt = 1; ; attempt++)
|
||||
{
|
||||
// A part as long as the file was complete when the last attempt stopped: only its hash is left to check.
|
||||
if (!File.Exists(part) || new FileInfo(part).Length < frame.Size) await FetchAsync(frame, "original", part, cancellationToken).ConfigureAwait(false);
|
||||
if (!File.Exists(part) || new FileInfo(part).Length < frame.Size) await FetchAsync(frame, "original", part, resume: true, cancellationToken).ConfigureAwait(false);
|
||||
if (await TitanoClient.HashFileAsync(part, cancellationToken).ConfigureAwait(false) == sha)
|
||||
{
|
||||
File.Move(part, path, overwrite: true);
|
||||
@@ -355,17 +356,18 @@ public sealed class RenderNodeClient : IAsyncDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches a frame resource into <paramref name="path"/>, appending to what an earlier attempt left there. A dropped
|
||||
/// connection or a busy server is retried, resuming where the file ends (up to <see cref="RenderNodeOptions.DownloadRetries"/> times,
|
||||
/// the wait doubling from <see cref="RenderNodeOptions.RetryDelay"/>).
|
||||
/// Fetches a frame resource into <paramref name="path"/>. A dropped connection or a busy server is retried (up to
|
||||
/// <see cref="RenderNodeOptions.DownloadRetries"/> times, the wait doubling from <see cref="RenderNodeOptions.RetryDelay"/>);
|
||||
/// with <paramref name="resume"/> (a download its hash verifies) each attempt appends to what the last one left,
|
||||
/// otherwise it starts over.
|
||||
/// </summary>
|
||||
private async Task FetchAsync(ManifestFrame frame, string kind, string path, CancellationToken cancellationToken)
|
||||
private async Task FetchAsync(ManifestFrame frame, string kind, string path, bool resume, CancellationToken cancellationToken)
|
||||
{
|
||||
for (var attempt = 0; ; attempt++)
|
||||
{
|
||||
try
|
||||
{
|
||||
await using var file = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
|
||||
await using var file = new FileStream(path, resume ? FileMode.OpenOrCreate : FileMode.Create, FileAccess.ReadWrite, FileShare.None);
|
||||
await _client.DownloadFrameAsync(frame.Id, kind, file, null, cancellationToken).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user