Attachments are dropped at 20 MiB uncompressed even when the compressed request fits Sentry's limits
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start with the referenced paths in src/Sentry/Internal/Http/HttpTransportBase.cs, CachingTransport.cs, and GzipBufferedRequestBodyHandler.cs, then trace how rejected envelopes are handled and how client reports record dropped attachments. Compare the retry behavior with the heap dump file deletion ordering described in #5481. Done means rejected uploads retry once with the event but no attachments, record attachment drops, and work for buffered, streamed, uncompressed, and cached requests.
Written by the indexing model from the issue text.
Description
Before sending, the SDK drops any attachment whose uncompressed size is over MaxAttachmentSize (20 MiB by default). Sentry's ingestion limits are now higher, and they're measured differently:
- at most 40 MB per compressed request;
- at most 200 MB of uncompressed attachments per event (docs).
So the SDK drops attachments that Sentry would accept. Heap dumps hit this the hardest (#4007). In a repro on main, a 59 MB .gcdump gzipped to 13.6 MB, well within the 40 MB request limit, but the SDK still dropped it.
When the SDK drops an attachment, the only sign is a warning in the SDK's own diagnostic log. The event has no marker, and no client report is recorded (HttpTransportBase.cs#L149-L160). For heap dumps, main also deletes the file afterwards (#5481), so the dump is gone with no trace in Sentry.
The server limits have already changed once without the SDK following. Whatever we do here shouldn't leave us in the same position the next time they change.
What happens when the server says no
If a request is over the server's limits, the server rejects the whole envelope, event included:
- A
413goes throughHandleFailure, which records every item in the envelope as asend_errordiscard and resends nothing (HttpTransportBase.cs#L347-L349, #L494-L505). - For a streamed request, the server doesn't wait for the whole body. It resets the connection once the limit is passed, which shows up as a broken pipe (CachingTransport.cs#L310-L316).
So "just raise MaxAttachmentSize" isn't enough on its own. An attachment that's too big would then take its event down with it.
Option A: check the server's limits in the SDK
Check both limits at the point where each size is known:
- Uncompressed: the envelope's attachments must total ≤ 200 MB. This is known before serialization.
- Compressed: the request must be ≤ 40 MB. With the default
GzipBufferedRequestBodyHandler, the whole compressed body is already in aMemoryStream, so its exact length is known before the request goes out (GzipBufferedRequestBodyHandler.cs#L45-L60). If it's over, drop the attachments and send the event without them.
Downsides:
- The SDK hardcodes the server's numbers, so this goes stale the next time they change, exactly as the 20 MiB default did.
- It only covers the buffered default.
RequestBodyCompressionBuffered = falsestreams the body, so the compressed size isn't known until it has been sent, and only the 200 MB check is possible. A 150 MB attachment passes that check, and if it compresses to over 40 MB, the server rejects the whole request, event included.NoCompressionneeds its own rule as well.
Option B (recommended): let the server decide, and retry without attachments
Send the event with its attachments as normal. If the server rejects the request (a 413, or the connection reset mid-upload), remove the attachments, resend the event once, and record a client report for the dropped attachments (DataCategory.Attachment).
The server stays the only authority on its own limits, so:
- the SDK hardcodes no server numbers, and nothing breaks when the limits change again;
- it works the same for buffered, streamed and uncompressed requests;
- the event always gets through, which is the part worth keeping for heap dumps (see the discussion in #4007).
Costs:
- Wasted upload when a request is rejected: up to the point where the server cuts it off, roughly 40 MB compressed.
- The retry removes every attachment. A
413doesn't say which item was too big. - Ordering. The resent event doesn't need the dump file, but heap dump files are deleted on close (#5481), so the retry has to be decided before that deletion, or the deletion has to come after it.
- Offline caching.
CachingTransportalready treats a broken pipe as a server rejection. The retry has to fit in there, so that a cached envelope that's too big is resent as event-only and not dropped.
I recommend B as the permanent fix. It solves the problem once, where A has to be revisited every time the server changes.
Either way
MaxAttachmentSizestays. The attachments spec says SDKs MUST discard items larger than it. It's a cap the user sets on what they're willing to send (bandwidth, cost), not a copy of the server's limit. Its default is what blocks heap dumps today, so we still need to decide whether to raise the default or to exempt heap dumps. Heap dumps are already an explicit, experimental opt-in.- Fix the doc comment.
MaxAttachmentSizestill says attachments are "limited to 20mb (compressed) on Relay" (SentryOptions.cs#L1232-L1239). It shouldn't quote server numbers at all. - Make drops visible. Record a client report whenever an attachment is dropped, whether by
MaxAttachmentSizeor by a retry. Telling the user on the event itself (for example, a context with the file name and size) would help more, but after a rejection the event is already serialized, so that means rebuilding it for the retry.
Out of scope
Attachments that can never fit in an envelope. Those need the experimental resumable-upload path described in #4007, and that's a separate piece of work.
Relates to #4007
- Dominant language
- C#
- Stars
- 775
- Forks
- 262
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 118
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from getsentry/sentry-dotnet
-
chore: remove stale IL3050/IL3053 workaround from the iOS samplePossibly taken A pull request linked to this issue is open or already merged. OpenState: Needs Discussion
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
getsentry/sentry-dotnet#6071 · 1 comment ·
Maintainers usually reply within 1 day
-
Heap dumps: every SDK shutdown logs "Error waiting for GarbageCollectionMonitor task to complete"Possibly taken @pcbeingused33 claimed this today. OpenState: Needs Discussion
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
getsentry/sentry-dotnet#6039 · 3 comments ·
Maintainers usually reply within 1 day
-
.NET Platform: Android Task
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
getsentry/sentry-dotnet#6020 · 3 comments ·
Maintainers usually reply within 1 day
-
Move the Blazor WebAssembly sample off the deprecated DevServerPossibly taken A pull request linked to this issue is open or already merged. Open.NET Framework: Blazor
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
getsentry/sentry-dotnet#5906 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Docs MSBuild Needs Docs Update
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
getsentry/sentry-dotnet#5691 · 1 comment ·
Maintainers usually reply within 1 day
All issues in getsentry/sentry-dotnet
Similar issues
-
In-car displays show 0 km/h and P while the AV drivesPossibly taken @bazilinskyy claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
bazilinskyy/coupled-sim#366 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
BaryoDev/umbraco-pwa#196 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
microsoft/fluentui-blazor#5688 ·
Maintainers usually reply within 1 day
-
bug flaky lsp-transport small
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day