fix(attachments): flush scope on updating attachments - #1934
fix(attachments): flush scope on updating attachments#1934JoshuaMoelans wants to merge 6 commits into
Conversation
`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>
…nt_updates_on_scope
Codecov Report❌ Patch coverage is 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:
|
|
@sentry review |
|
|
||
| SENTRY_WITH_SCOPE_MUT (scope) { | ||
| sentry__attachment_set_type_n(attachment, type, type_len); | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
There are quite a few changes ahead if we want to do that, but I'd eventually
- replace heap-allocated
sentry_attachment_tobjects withsentry_value_t-backed value types, - replace global scope mutex with fine-grained read-write locks, and
- replace backend flush functions with scope observers.
jpnurmi
left a comment
There was a problem hiding this comment.
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.
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-streamwhich gets a Preview button (whereas theapplication/ztsdwould 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: