Session Replay: session segment ID can repeat after an error converts buffer mode

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

Start in ReplayIntegration.captureCurrentReplay and follow convert() into BufferCaptureStrategy.start; then read the queued replay tasks for pause, configuration_changed, and add_frame that mutate currentSegment. Reproduce with a test where one of those tasks is queued when an error converts the strategy, then assert session segment IDs do not repeat. Done when the next session ID is derived from the segment actually sent via onSegmentSent, not from a stale copy, and the replay test passes.

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

描述

Android Bug Platform: Java Replays

Problem

When an error converts buffer mode to session mode, the session can send two segments with the same segment ID.

captureCurrentReplay calls convert() on the caller thread. convert() gives currentSegment to SessionCaptureStrategy.start(segmentId = currentSegment) immediately. But tasks that are still in the queue of the replay executor can change the counter of the buffer strategy after that copy:

The capture_replay task then sends the current segment with the changed counter. After that, the callback does activeStrategy.currentSegment++ on the copy that is out of date.

Example

  1. Buffer mode. No segments are buffered, so currentSegment is 0.
  2. The user rotates the device. A configuration_changed task is in the queue.
  3. An error occurs before that task runs. convert() starts the session with segment ID 0.
  4. The configuration_changed task buffers segment 0. The buffer counter becomes 1.
  5. The capture_replay task sends buffered segment 0 and current segment 1. The callback sets the session counter from 0 to 1.
  6. The next session segment also has ID 1.

Proposed fix

Set the next session segment ID from the ID of the segment that the flush sent (for example, pass it to onSegmentSent and set currentSegment = sentId + 1). Do not increment a copy.

Add a test: a configuration_changed or pause task in the queue when an error converts the strategy. Then the session segment IDs must not repeat.

Found while reviewing #6542. That PR can also change the counter in a queued task (a clock jump deletes buffered segments). The bug is on main without it.

主要语言
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 摘要。