Repository navigation
fix: drop attachments whose stream turns out empty when the envelope is sent - #5787
Draft
bitsandfoxes wants to merge 3 commits into
Draft
bitsandfoxes wants to merge 3 commits into
bitsandfoxes wants to merge 3 commits into
Conversation
Non-seekable attachment streams have no known length when the envelope is created, so the existing zero-length check can't catch them. Skip the item at serialization time, once its payload is buffered and before its header is written. Co-Authored-By: Claude <noreply@anthropic.com>
Keeps explicit length-0 items, as in the envelope spec's framing examples, serializing as before. Co-Authored-By: Claude <noreply@anthropic.com>
Deserialization strips the length header, so keying the drop on an unknown length also dropped deliberately empty attachments after a cache round trip. Key it on the payload built from a stream of unknown length instead. Co-Authored-By: Claude <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5787 +/- ##
==========================================
+ Coverage 76.13% 76.16% +0.02%
==========================================
Files 528 528
Lines 19579 19590 +11
Branches 3829 3835 +6
==========================================
+ Hits 14906 14920 +14
+ Misses 3791 3789 -2
+ Partials 882 881 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An attachment whose content is a non-seekable stream was sent with
length: 0when the stream turned out empty. Relay then stored an empty file on the event.Envelope.AddEnvelopeItemFromAttachmentskips empty attachments only whenstream.TryGetLength()returns0. A non-seekable stream reportsnull, so the item was kept, and its header gotlength: 0once the payload was buffered at serialization. sentry-unity hits this on purpose: its screenshot content returns a non-seekable stream soEnvelope.FromEventdoesn't block waiting for the end-of-frame capture. When the screenshot is discarded (SetBeforeSendScreenshotreturnsnull), times out or fails, the event shows an emptyscreenshot.jpg(see getsentry/sentry-unity#2835).The fix acts at serialization, the first point where the payload size is known.
Envelope.Serialize/SerializeAsyncskip an attachment item, header and trailing newline included, when it was built from an attachment stream of unknown length and its buffered payload is empty. A warning is logged in the same wording as the checks at envelope creation.length: 0are left alone. The envelope spec's framing example "Envelope with 2 empty attachments", whichEnvelopeTestsmirrors, keeps serializing as before.EnvelopeItem.Serialize/SerializeAsynckeep their signatures and behaviour (they always write). They delegate to new internal overloads that return whether the item was written, soEnvelopecan skip the item's trailing newline too. No public API change.length, so the check keys on the payload type, not the header, and a deliberately empty attachment survives the round trip as onmain.An envelope whose only item is dropped, e.g. an empty non-seekable attachment sent via
Hub.CaptureAttachment, goes out as a header-only envelope. Relay parses that and returns 200 without storing anything (handle_managed_envelopereturns early whenenvelope.is_empty()), so the only cost is the request.No client report is recorded for the drop, matching the existing drops at creation.
Tests:
AttachmentSerializationTestsgets a non-seekable empty stream attached throughEnvelope.FromEvent, serialized sync and async and deserialized again. Both tests failed before the change. A third test round-trips a known-length empty attachment through serialize, deserialize and serialize, and checks that it's kept.🤖 Generated with Claude Code