Skip to content

Commit 106eb5a

Browse files
authored
tart push: re-try when encountering errors when pushing disk layers (#888)
* tart push: re-try when encountering errors when pushing disk layers * Only re-try on URLError
1 parent 10bf706 commit 106eb5a

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

Sources/tart/OCI/Layerizer/DiskV2.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22
import Compression
33
import System
4+
import Retry
45

56
class DiskV2: Disk {
67
private static let bufferSizeBytes = 4 * 1024 * 1024
@@ -28,8 +29,19 @@ class DiskV2: Disk {
2829
let compressedData = try (data as NSData).compressed(using: .lz4) as Data
2930
let compressedDataDigest = Digest.hash(compressedData)
3031

31-
if try await !registry.blobExists(compressedDataDigest) {
32-
_ = try await registry.pushBlob(fromData: compressedData, chunkSizeMb: chunkSizeMb, digest: compressedDataDigest)
32+
try await retry(maxAttempts: 5, backoff: .exponentialWithFullJitter(baseDelay: .seconds(5), maxDelay: .seconds(60))) {
33+
if try await !registry.blobExists(compressedDataDigest) {
34+
_ = try await registry.pushBlob(fromData: compressedData, chunkSizeMb: chunkSizeMb, digest: compressedDataDigest)
35+
}
36+
} recoverFromFailure: { error in
37+
if error is URLError {
38+
print("Error: \(error.localizedDescription)")
39+
print("Attempting to re-try...")
40+
41+
return .retry
42+
}
43+
44+
return .throw
3345
}
3446

3547
// Update progress using a relative value

Sources/tart/VMStorageOCI.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,14 @@ class VMStorageOCI: PrunableStorage {
208208

209209
try await tmpVMDir.pullFromRegistry(registry: registry, manifest: manifest, concurrency: concurrency, localLayerCache: localLayerCache)
210210
} recoverFromFailure: { error in
211-
if error is RuntimeError {
212-
return .throw
213-
}
211+
if error is Retryable {
212+
print("Error: \(error.localizedDescription)")
213+
print("Attempting to re-try...")
214214

215-
print("Error: \(error.localizedDescription)")
216-
print("Attempting to re-try...")
215+
return .retry
216+
}
217217

218-
return .retry
218+
return .throw
219219
}
220220
try move(digestName, from: tmpVMDir)
221221
transaction.finish()

0 commit comments

Comments
 (0)