Android Replay: BufferCaptureStrategy.stop() can persist replay state after deleting replay cache dir
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 70/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- android, kotlin
- 领域
- mobile-dev
调研方向
从 BufferCaptureStrategy.kt 和 ReplayCache.kt 开始,沿着 currentSegment setter 和 persistSegmentValues() 跟踪 BufferCaptureStrategy.stop()。重现 buffering replay teardown 路径,尤其是在删除 replay cache 目录之后,并验证停止 replay 后不再记录 No such file or directory 错误。
由索引模型根据 Issue 内容生成。
描述
Problem Statement
Android Session Replay can throw an internal error during replay teardown:
Failed to execute task CaptureStrategy.runInBackground
java.io.IOException: No such file or directory
...
at io.sentry.android.replay.ReplayCache.persistSegmentValues
...
at io.sentry.android.replay.capture.BufferCaptureStrategy.stop
This appears to happen when stopping a buffering replay.
Likely root cause
BufferCaptureStrategy.stop() currently deletes the replay cache directory and then updates replay state in the same task:
- delete replay cache dir
- set
currentSegment = -1
The currentSegment setter persists state through ReplayCache.persistSegmentValues(...).
On the replay worker thread, that persistence runs inline, so it can try to recreate/write .ongoing_segment after the replay directory has already been deleted.
That leads to:
java.io.IOException: No such file or directory
at java.io.File.createNewFile
at io.sentry.android.replay.ReplayCache.persistSegmentValues
Why this matters
This is at least noisy internal error logging, but it may also contribute to brittle replay lifecycle behavior in manual/custom flows that use combinations of:
flush()pause()stop()startBuffering()
In our investigation, this showed up while testing a custom User Feedback + Replay workaround, where replay behavior was already timing-sensitive.
Relevant code path
Conceptually, the flow is:
BufferCaptureStrategy.stop()FileUtils.deleteRecursively(replayCacheDir)currentSegment = -1persistSegmentValues(...)ongoingSegmentFile?.createNewFile()- parent folder no longer exists
Expected behavior
Stopping replay should not try to persist replay state into a directory that has already been deleted.
Actual behavior
Replay teardown logs No such file or directory from ReplayCache.persistSegmentValues.
Suggested fix direction
Any of these would likely resolve it:
- clear/persist mutable state before deleting the replay directory
- mark the cache closed before state mutation can persist
- guard
persistSegmentValuesagainst a missing/deleted parent directory during teardown - avoid persisting teardown sentinel values like
currentSegment = -1once shutdown has begun
Customer-visible context
This was observed during a real customer reproduction involving Android Session Replay plus custom in-app User Feedback, where the workaround flow exercised replay stop/restart behavior repeatedly.
Logs
Failed to execute task CaptureStrategy.runInBackground
java.io.IOException: No such file or directory
at java.io.UnixFileSystem.createFileExclusively0(Native Method)
at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:373)
at java.io.File.createNewFile(File.java:1022)
at io.sentry.android.replay.ReplayCache.persistSegmentValues$sentry_android_replay_release(ReplayCache.kt:290)
at io.sentry.android.replay.capture.BaseCaptureStrategy$special$$inlined$persistableAtomic$default$2$2.invoke(BaseCaptureStrategy.kt:240)
at io.sentry.android.replay.capture.BaseCaptureStrategy$special$$inlined$persistableAtomic$default$2.runInBackground(BaseCaptureStrategy.kt:227)
at io.sentry.android.replay.capture.BaseCaptureStrategy$special$$inlined$persistableAtomic$default$2.setValue(BaseCaptureStrategy.kt:239)
at io.sentry.android.replay.capture.BaseCaptureStrategy.setCurrentSegment(BaseCaptureStrategy.kt:88)
at io.sentry.android.replay.capture.BufferCaptureStrategy.stop$lambda$0(BufferCaptureStrategy.kt:84)
- 主要语言
- Kotlin
- 星标
- 1.4k
- 派生
- 478
- 平均合并
- 3 天 2 小时
- 30 天内合并 PR
- 70
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
getsentry/sentry-java 的其他 Issue
-
Improvement Java Platform: Java
难度 2/5 1-3 小时 新手友好度 75/100
getsentry/sentry-java#6145 · 1 条评论 ·
-
Bug Java Platform: Java
难度 2/5 1-3 小时 新手友好度 78/100
getsentry/sentry-java#6138 · 1 条评论 ·
-
Feature Java Platform: Java Spans
难度 2/5 1-3 小时 新手友好度 68/100
getsentry/sentry-java#5984 · 1 条评论 ·
-
Android Task Traces
难度 2/5 1-3 小时 新手友好度 68/100
getsentry/sentry-java#5376 · 1 条评论 ·
-
Android Docs Errors
难度 2/5 1-3 小时 新手友好度 64/100
getsentry/sentry-java#5375 · 1 条评论 ·
查看 getsentry/sentry-java 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
johanhaleby/occurrent#1120 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
2 rename bugs 未关闭bug
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 68/100
ankidroid/Anki-Android#21999 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
openwallet-foundation/multipaz#2028 ·