fix: make attachment payloads replayable - #5511
Open
XAN9xXx wants to merge 3 commits into
Open
Conversation
Create independent streams for byte and reusable file attachments. Lazily buffer one-shot streams so multiple transports can serialize the same envelope without consuming a shared stream. Fixes getsentry#5499
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6f1ac20. Configure here.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #5511 +/- ##
==========================================
- Coverage 74.74% 74.74% -0.01%
==========================================
Files 513 515 +2
Lines 18829 18887 +58
Branches 3682 3690 +8
==========================================
+ Hits 14074 14117 +43
- Misses 3875 3885 +10
- Partials 880 885 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.

Summary
Fixes #5499.
When Spotlight is enabled, the same envelope can be serialized by both the
primary transport and the Spotlight transport. Attachment payloads previously
shared a single stream, so one serialization could consume the content before
the other transport read it.
This change makes attachment payloads replayable:
serialization.
serialization.
files are buffered in memory on first serialization and reuse that buffer
for subsequent serializations.
Implementation notes
The buffering path obtains the source stream while creating the envelope item
for length validation, but does not read its content until the first
serialization. The resulting buffer is shared by repeated and concurrent
serializations.
Exact type checks are used for the built-in byte and file attachment types
because derived or custom implementations may return streams with different
lifetime or replayability behavior.
Envelope and transport ownership semantics are unchanged.
Testing
Regression coverage includes: