Skip to content

Comments

fix: Transport correctly handling 4xx and 5xx#6618

Merged
philipphofmann merged 24 commits intogetsentry:mainfrom
dfed:main
Dec 18, 2025
Merged

fix: Transport correctly handling 4xx and 5xx#6618
philipphofmann merged 24 commits intogetsentry:mainfrom
dfed:main

Conversation

@dfed
Copy link
Contributor

@dfed dfed commented Oct 30, 2025

📜 Description

If an upload receives a 4xx error, Sentry should assume that a retry will not succeed and drop it on the floor. Currently Sentry will retry the upload (seemingly forever), which means that a 4xx error on upload will prevent future uploads from succeeding.

💡 Motivation and Context

This PR represents the shortest-path resolution to #6612. I'd prefer a solution where a 4xx error didn't cause a silent failure, or a solution where breadcrumb were automatically truncated. But this change is simple and unsticks existing clients, which seems like a good thing.

💚 How did you test it?

I didn't.

📝 Checklist

You have to check all boxes before merging:

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@philprime
Copy link
Member

@philipphofmann are you going to pick this up?

@philipphofmann
Copy link
Member

@philprime, yes, I plan to next week. I mean, you or anybody else can also pick it up if you have bandwidth.

@philipphofmann
Copy link
Member

I manually tested capturing a message with the iOS-Swift sample app

let message = Data(repeating: 0, count: 1024*1024*2) // 2 MB message
let string = message.base64EncodedString()
let eventId = SentrySDK.capture(message: string)

And the transport successfully deleted the envelope when getting a 400 from Relay.

Doing the same thing on the main branch, led to filling up the chache until the faulty envelope with the too large message finally gets deleted due to cache overflow.

@philipphofmann philipphofmann marked this pull request as ready for review December 16, 2025 15:45
@philipphofmann philipphofmann changed the title Do not retry 4xx uploads fix: Transport correctly handling 4xx and 5xx Dec 16, 2025
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Test helper missing new `send_error` discard reason case

The sentryDiscardReasonForString helper function is missing a case for kSentryDiscardReasonNameSendError, which was added by this PR. Since the function has a default case that calls fatalError("Unsupported reason: \(reason)"), any test that uses givenRecordedLostEvents() with a discarded event containing the send_error reason will crash at runtime. The function needs to handle .sendError to match the new discard reason added to the production code.

Tests/SentryTests/Networking/SentryHttpTransportTests.swift#L1055-L1077

private func sentryDiscardReasonForString(_ reason: String) -> SentryDiscardReason {
switch reason {
case kSentryDiscardReasonNameBeforeSend:
return .beforeSend
case kSentryDiscardReasonNameEventProcessor:
return .eventProcessor
case kSentryDiscardReasonNameSampleRate:
return .sampleRate
case kSentryDiscardReasonNameNetworkError:
return .networkError
case kSentryDiscardReasonNameQueueOverflow:
return .queueOverflow
case kSentryDiscardReasonNameCacheOverflow:
return .cacheOverflow
case kSentryDiscardReasonNameRateLimitBackoff:
return .rateLimitBackoff
case kSentryDiscardReasonNameInsufficientData:
return .insufficientData
default:
fatalError("Unsupported reason: \(reason)")
}
}

Fix in Cursor Fix in Web


@philipphofmann philipphofmann merged commit 69bb7e3 into getsentry:main Dec 18, 2025
175 of 186 checks passed
@dfed
Copy link
Contributor Author

dfed commented Dec 18, 2025

Thank you all for getting this over the line! Excited for this 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Use this label to trigger all PR workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants