Session Replay: buffered segment can be sent with the wrong video after buffer rotation

未关闭
#6,741 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
62/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
android, kotlin
领域
mobile

调研方向

Start in sentry-android-replay/src/main/java/io/sentry/android/replay/capture/BufferCaptureStrategy.kt at the bufferedSegments.rotate call and read how remaining segments are re-assigned IDs while videoFile stays fixed. Then read ReplayCache.kt (getReplayOrDefaultFile/createVideoOf around line 140-151) to see where the $segmentId.mp4 name is built and deleted, plus ReplayCache.fromDisk and deleteExceptSegmentVideos for the recovery path. Write the failing test first: two buffered segments, expire the first, trigger an error, and assert the buffered segment keeps its own video; done means that test passes and disk recovery still finds all videos.

由索引模型根据 Issue 内容生成。

描述

Android Bug Platform: Java Replays

Problem

In buffer mode, an error can send a buffered segment with the wrong video.

Each video is stored at "$segmentId.mp4". When bufferedSegments.rotate removes an expired segment, it gives the remaining segments new IDs, but their videoFile does not change. Then currentSegment can be equal to the ID in the file name of a segment that is still buffered.

When an error occurs, the capture_replay task first encodes the current segment to "$currentSegment.mp4". createVideoOf deletes the file that is already there. After that, bufferedSegments.capture() sends the buffered segment, which now points to the new video.

Example

  1. Buffer mode. The user puts the app in the background. pause buffers segment 0 at 0.mp4.
  2. The user opens the app again and rotates the device. configuration_changed buffers segment 1 at 1.mp4. currentSegment is 2.
  3. 30s after step 1, segment 0 expires. The rotation deletes 0.mp4. Segment 1 gets ID 0 but keeps 1.mp4. currentSegment is 1.
  4. An error occurs before segment 1 expires. The current segment is encoded to 1.mp4, and the old content of that file is deleted.
  5. The replay sends segment 0 and segment 1 with the same video. The video of the buffered segment is lost.

Proposed fix

Give each video a file name that does not depend on the segment ID that is sent, for example a counter that only increases, or a UUID. Make sure that crash recovery (ReplayCache.fromDisk and deleteExceptSegmentVideos) still finds the videos.

First, add a test on main that fails: two buffered segments, the first one expires, then an error occurs. The buffered segment must keep its own video.

Found while reviewing #6542. The bug is on main without that PR.

主要语言
Kotlin
星标
1.4k
派生
483
平均合并
2 天 54 分钟
30 天内合并 PR
207

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

getsentry/sentry-java 的其他 Issue

查看 getsentry/sentry-java 的全部 Issue

相似的 Issue

更多 Kotlin Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。