Skip to content

Commit 38f5ed9

Browse files
authored
feat(kinesis): fix retry logic for request-level errors (#4167)
1 parent d4d9557 commit 38f5ed9

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

AmplifyClients/AmplifyKinesisClient/Sources/Support/RecordClient.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ actor RecordClient {
9393
}
9494

9595
private func handleFailedRequest(_ records: [Record]) async {
96-
let retryable = records.filter { $0.retryCount + 1 < maxRetries }
97-
let expired = records.filter { $0.retryCount + 1 >= maxRetries }
96+
let retryable = records.filter { $0.retryCount < maxRetries }
97+
let expired = records.filter { $0.retryCount >= maxRetries }
9898

9999
do {
100100
try await storage.incrementRetryCount(ids: retryable.map(\.id))
@@ -104,7 +104,7 @@ actor RecordClient {
104104
let streamName = records[0].streamName
105105
logger.warn(
106106
"Deleted \(expired.count) records from stream \(streamName) "
107-
+ "that exceeded retry limit of \(maxRetries) after failed request"
107+
+ "that exceeded retry limit of \(maxRetries) after failed retries"
108108
)
109109
}
110110
} catch {

AmplifyClients/AmplifyKinesisClient/Tests/UnitTests/RecordClientFlushTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class RecordClientFlushTests: XCTestCase {
102102
let allRecords = try await storage.getRecordsByStream().flatMap { $0 }
103103
let record2Id = allRecords[1].id
104104
let record3Id = allRecords[2].id
105+
106+
// Increment to maxRetries (3) so they are expired on next failed flush
107+
try await storage.incrementRetryCount(ids: [record2Id, record3Id])
105108
try await storage.incrementRetryCount(ids: [record2Id, record3Id])
106109
try await storage.incrementRetryCount(ids: [record2Id, record3Id])
107110

0 commit comments

Comments
 (0)