Skip to content

fix(attachments): flush scope on updating attachments - #1934

Open
JoshuaMoelans wants to merge 6 commits into
masterfrom
joshua/fix/attachment_updates_on_scope
Open

fix(attachments): flush scope on updating attachments#1934
JoshuaMoelans wants to merge 6 commits into
masterfrom
joshua/fix/attachment_updates_on_scope

Conversation

@JoshuaMoelans

@JoshuaMoelans JoshuaMoelans commented Jul 31, 2026

Copy link
Copy Markdown
Member

Fixes #1933

Updates to attachments weren't flushed to the scope (only when adding it with sentry_attach_file). This caused updates to attachments to only apply on non-fatal events, since the native backend only knows about the state of the attachment from right before attaching it.

This fixes both questions in the original issue; attachment names are synced & so are the content_types, which initially made Sentry backend interpret the file as the default application/octet-stream which gets a Preview button (whereas the application/ztsd would not)

From the flow that UE hits on adding attachments, we see the same attach -> set_filename -> set_content_type flow that we now fix with scope syncing:

void FGenericPlatformSentrySubsystem::AddFileAttachment(TSharedPtr<ISentryAttachment> attachment)
{
	TSharedPtr<FGenericPlatformSentryAttachment> platformAttachment = StaticCastSharedPtr<FGenericPlatformSentryAttachment>(attachment);

	sentry_attachment_t* nativeAttachment =
		sentry_attach_file(TCHAR_TO_UTF8(*platformAttachment->GetPath()));

	if (!platformAttachment->GetFilename().IsEmpty())
		sentry_attachment_set_filename(nativeAttachment, TCHAR_TO_UTF8(*platformAttachment->GetFilename()));

	if (!platformAttachment->GetContentType().IsEmpty())
		sentry_attachment_set_content_type(nativeAttachment, TCHAR_TO_UTF8(*platformAttachment->GetContentType()));

	platformAttachment->SetNativeObject(nativeAttachment);

	attachments.Add(platformAttachment);
}

JoshuaMoelans and others added 5 commits July 31, 2026 10:10
`sentry_attachment_set_filename`, `_set_type` and `_set_content_type` mutated
scope-owned attachments without locking or flushing the scope. The native
backend only rewrites `<run>/__sentry-attachments` on a scope flush, so the
crash daemon read a manifest that still carried the physical basename and the
attachment type/content type from when the attachment was added.

Split each setter into a raw internal mutator and a public wrapper that mutates
under the scope lock and flushes the backend on unlock. `sentry__attachments_add_path`
uses the raw mutators, keeping options attachments, hint attachments and the
crashpad old-run envelope builder off the scope lock.

Fixes #1933

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.41379% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.79%. Comparing base (5bac907) to head (ba60934).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1934      +/-   ##
==========================================
+ Coverage   75.74%   75.79%   +0.05%     
==========================================
  Files          93       93              
  Lines       22128    22155      +27     
  Branches     3939     3945       +6     
==========================================
+ Hits        16760    16792      +32     
+ Misses       4484     4477       -7     
- Partials      884      886       +2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JoshuaMoelans
JoshuaMoelans marked this pull request as ready for review July 31, 2026 10:59
@JoshuaMoelans

Copy link
Copy Markdown
Member Author

@sentry review

Comment thread src/sentry_attachment.c

SENTRY_WITH_SCOPE_MUT (scope) {
sentry__attachment_set_type_n(attachment, type, type_len);
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

open q: both places where we now WITH_SCOPE are additional overhead, although these (probably) don't get called that often. This overhead is acceptable for the attachments that actually are on the global scope, but we also do it for those that are in the local scopes (or hint attachments).
We could walk the global attachments list to check if a scope lock is necessary, but this also seems like overhead (albeit less so than a full scope flush), so it might be worth considering.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There are quite a few changes ahead if we want to do that, but I'd eventually

  • replace heap-allocated sentry_attachment_t objects with sentry_value_t-backed value types,
  • replace global scope mutex with fine-grained read-write locks, and
  • replace backend flush functions with scope observers.

@JoshuaMoelans
JoshuaMoelans requested a review from jpnurmi August 3, 2026 14:55

@jpnurmi jpnurmi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this is fine for now.

There's an increasing number of reasons for moving towards sentry_value-based attachments and potentially getting rid of the whole backend flush-function altogether, but such changes would not happen overnight. This change helps until then.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native backend uses physical attachment filename for hard crashes, instead of the name passed to USentryLibrary::CreateSentryAttachmentWithData()

2 participants