Skip to content

Crash reporting: keep capture armed through a panic, retry unreadable envelopes, read nothing without a DSN - #168

Merged
GLinnik21 merged 1 commit into
mainfrom
fix/crash-report-followups
Sep 19, 2026
Merged

GLinnik21 merged 1 commit into
mainfrom
fix/crash-report-followups

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

Three follow-ups to #155.

A: a panic unwinding out of plex_run switched off native capture before the abort

Defect. telemetry::native::Guard's Drop always ran stop() and remove_database(). A panic that unwinds plex_run's frame drops App and the Guard with it, which stopped the native backend and deleted its database. Then the extern "C" boundary aborted with no native handler installed, so no envelope was written.
Red test. telemetry::native::tests::a_guard_dropped_while_unwinding_keeps_the_native_database failed with: a Guard dropped while unwinding a panic deleted the native database, so the abort that follows is captured by nothing.
Fix. Drop for Guard now returns early when std::thread::panicking(). A clean exit still shuts the backend down exactly as before, and a_guard_dropped_on_a_clean_exit_tears_the_backend_down covers that branch. The crashtest=panic doc in dev.rs said a straight panic! loses the envelope, which is no longer true, so it now says so. The extern "C" callback path stays because it matches how a real panic under libav dies.

B: a native envelope that briefly failed to READ was deleted

Defect. In read_pending, any failure in the metadata, open, read or parse chain was counted as rejected and the file was deleted. A transient I/O error lost the crash report for good.
Red test. telemetry::native::tests::an_unreadable_envelope_is_deferred_and_a_malformed_one_deleted (a valid envelope made mode 0000, next to a malformed one) failed with: an envelope that failed to OPEN was deleted instead of being left for the next boot.
Fix. A new load_envelope sorts each file into Ready, Rejected, Deferred or Vanished:

  • Rejected (deleted as before): not a regular file, over MAX_RECORD, or bytes that were read and then refused by the parser.
  • Deferred (left on disk, counted in the log line as deferred=): a metadata, open or read I/O error.
  • Vanished (ignored): the file disappeared between the listing and the read.

A file that stays unreadable for good is never deleted and costs one failed read per boot. The doc comment says this.

C: the crash log was read in a build with no Sentry DSN

Defect. recover_pending checked only consent::allows_errors(). A build with no DSN still read the crash log and spooled records that could never be sent. It also moved the watermark past those records.
Red test. telemetry::crashreport::tests::a_build_without_a_sentry_dsn_reads_no_crash_data failed with: a build with no Sentry DSN read the crash log and spooled 1313 bytes it can never send.
Fix. A single gate, crashreport::may_read_crash_data() (allows_errors() && has_sentry()), now guards both the crash log in recover_pending and the native envelopes in native::read_pending. native::import_all goes through read_pending, so it is covered too. A no-DSN build reads nothing, writes no watermark and deletes no envelope. To make these paths testable, recover_pending_at(path) and read_pending_in(dir) were extracted without changing behaviour.

Gates (run on the committed tree)

  • make check: passed (lib suite 3867 passed, hostsim 3914 passed, 0 failed). This checkout has no DSN configured, so test C ran its assertions rather than returning early.
  • CARGO_INCREMENTAL=0 cargo +nightly check --manifest-path rust-modules/Cargo.toml --lib --no-default-features: passed.
  • make (ARM cross-build): passed.

No TV was used.

🤖 Generated with Claude Code

… read no crash data without a DSN

Three follow-ups to the native crash-report import (#155):

- The telemetry Guard no longer stops the native backend or deletes its database while the
  thread is unwinding a panic. A panic that unwinds plex_run's frame aborts at the extern "C"
  boundary a moment later, and that abort is the crash the backend exists to capture. A clean
  exit still shuts it down as before.
- A pending native envelope that fails to READ (metadata, open or read I/O error) is left on
  disk for the next boot and counted as deferred=, instead of being deleted as malformed. Only
  a non-regular file, an oversized file, or bytes the parser refuses are deleted.
- Crash data (the crash log and the native envelopes) is read only when crash consent is given
  AND the build carries a Sentry DSN, through one gate, crashreport::may_read_crash_data. A
  no-DSN build reads nothing, moves no watermark and deletes no envelope.

Co-Authored-By: Claude Opus 5 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 19, 2026 18:25

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@GLinnik21
GLinnik21 merged commit d7f35ac into main Sep 19, 2026
5 checks passed
@GLinnik21
GLinnik21 deleted the fix/crash-report-followups branch September 19, 2026 18:35
GLinnik21 added a commit that referenced this pull request Sep 19, 2026
PR #168 made the telemetry `Guard`'s Drop check `std::thread::panicking()`
and return early, so a panic unwinding out of `plex_run` no longer tears
the native crash backend down before the boundary abort. `panic` still
exercises the extern "C" callback shape; `unwind` is the regression test
for the Guard fix itself, panicking directly in `crash_on_purpose` so the
unwind crosses `plex_run`'s own frame before aborting at its extern "C"
boundary.

Co-authored-by: Claude Opus 5 <[email protected]>
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.

2 participants