Skip to content

Commit 7c4b3d9

Browse files
authored
Merge pull request #2242 from DataDog/xgouchet/RUM-6060/prevent_upload_worker_loop
RUM-6060 stop upload worker on upload failure
2 parents eb6c153 + b3b46f5 commit 7c4b3d9

File tree

5 files changed

+685
-469
lines changed

5 files changed

+685
-469
lines changed

dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/data/upload/DataOkHttpUploader.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,16 @@ internal class DataOkHttpUploader(
172172
): UploadStatus {
173173
return when (code) {
174174
HTTP_ACCEPTED -> UploadStatus.Success(code)
175-
HTTP_BAD_REQUEST -> UploadStatus.HttpClientError(code)
176-
HTTP_UNAUTHORIZED -> UploadStatus.InvalidTokenError(code)
175+
176+
HTTP_UNAUTHORIZED,
177177
HTTP_FORBIDDEN -> UploadStatus.InvalidTokenError(code)
178-
HTTP_CLIENT_TIMEOUT -> UploadStatus.HttpClientRateLimiting(code)
179-
HTTP_ENTITY_TOO_LARGE -> UploadStatus.HttpClientError(code)
178+
179+
HTTP_CLIENT_TIMEOUT,
180180
HTTP_TOO_MANY_REQUESTS -> UploadStatus.HttpClientRateLimiting(code)
181+
182+
HTTP_BAD_REQUEST,
183+
HTTP_ENTITY_TOO_LARGE -> UploadStatus.HttpClientError(code)
184+
181185
HTTP_INTERNAL_ERROR,
182186
HTTP_BAD_GATEWAY,
183187
HTTP_UNAVAILABLE,

dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/data/upload/UploadStatus.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal sealed class UploadStatus(
1515
) {
1616

1717
internal class Success(responseCode: Int) : UploadStatus(shouldRetry = false, code = responseCode)
18+
1819
internal class NetworkError(throwable: Throwable) : UploadStatus(shouldRetry = true, throwable = throwable)
1920
internal class DNSError(throwable: Throwable) : UploadStatus(shouldRetry = true, throwable = throwable)
2021
internal class RequestCreationError(throwable: Throwable?) :
@@ -26,6 +27,7 @@ internal sealed class UploadStatus(
2627
internal class HttpServerError(responseCode: Int) : UploadStatus(shouldRetry = true, code = responseCode)
2728
internal class HttpClientRateLimiting(responseCode: Int) : UploadStatus(shouldRetry = true, code = responseCode)
2829
internal class UnknownHttpError(responseCode: Int) : UploadStatus(shouldRetry = false, code = responseCode)
30+
2931
internal class UnknownException(throwable: Throwable) : UploadStatus(shouldRetry = true, throwable = throwable)
3032

3133
internal object UnknownStatus : UploadStatus(shouldRetry = false, code = UNKNOWN_RESPONSE_CODE)

dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/data/upload/UploadWorker.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ internal class UploadWorker(
9797
RemovalReason.IntakeCode(uploadStatus.code),
9898
deleteBatch = !uploadStatus.shouldRetry
9999
)
100-
@Suppress("UnsafeThirdPartyFunctionCall") // safe to add
101-
taskQueue.offer(UploadNextBatchTask(taskQueue, sdkCore, feature))
100+
if (uploadStatus is UploadStatus.Success) {
101+
@Suppress("UnsafeThirdPartyFunctionCall") // safe to add
102+
taskQueue.offer(UploadNextBatchTask(taskQueue, sdkCore, feature))
103+
}
102104
}
103105
}
104106

dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/metrics/RemovalReason.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal sealed class RemovalReason {
1111
internal fun includeInMetrics(): Boolean {
1212
return this !is Flushed
1313
}
14-
internal class IntakeCode(private val responseCode: Int) : RemovalReason() {
14+
internal data class IntakeCode(private val responseCode: Int) : RemovalReason() {
1515
override fun toString(): String {
1616
return "intake-code-$responseCode"
1717
}

0 commit comments

Comments
 (0)