Skip to content

fix: make attachment payloads replayable - #5511

Open
XAN9xXx wants to merge 3 commits into
getsentry:mainfrom
XAN9xXx:fix/5499-stream-replayability
Open

fix: make attachment payloads replayable#5511
XAN9xXx wants to merge 3 commits into
getsentry:mainfrom
XAN9xXx:fix/5499-stream-replayability

Conversation

@XAN9xXx

@XAN9xXx XAN9xXx commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

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:

  • Built-in byte attachments obtain an independent stream for each
    serialization.
  • Built-in reusable file attachments open an independent file stream for each
    serialization.
  • Stream-backed, custom or derived attachment content, and delete-on-close
    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:

  • Repeated byte, file, and stream attachment serialization
  • Concurrent serialization
  • Synchronous and asynchronous serialization
  • Non-seekable and asynchronous-only streams
  • Custom and derived attachment content
  • Delete-on-close file attachments
  • Lazy buffering and cancellation behavior

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
@github-actions github-actions Bot added the risk: high PR risk score: high label Aug 26, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread src/Sentry/Protocol/Envelopes/Envelope.cs Outdated
@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.04918% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.74%. Comparing base (5cd6ad6) to head (a302317).

Files with missing lines Patch % Lines
src/Sentry/Protocol/Envelopes/Envelope.cs 56.25% 3 Missing and 4 partials ⚠️
...entry/Protocol/Envelopes/AttachmentSerializable.cs 57.14% 3 Missing ⚠️
...y/Protocol/Envelopes/BufferedStreamSerializable.cs 84.21% 3 Missing ⚠️
src/Sentry/Protocol/Envelopes/EnvelopeItem.cs 93.75% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spotlight transport shares and disposes envelope item streams with the inner transport

1 participant