Attachments are dropped at 20 MiB uncompressed even when the compressed request fits Sentry's limits

オープン
#6,044 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp
領域
api, backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

State: Needs Discussion

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 413 goes through HandleFailure, which records every item in the envelope as a send_error discard 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 a MemoryStream, 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 = false streams 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. NoCompression needs 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 413 doesn'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. CachingTransport already 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

  • MaxAttachmentSize stays. 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. MaxAttachmentSize still 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 MaxAttachmentSize or 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

主要言語
C#
スター
775
フォーク
262
平均マージ
1日 16時間
マージ済み PR(30日)
118

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

getsentry/sentry-dotnet のほかの issue

getsentry/sentry-dotnet の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。