Commit bbcf99a
fix(replay): Release MediaMuxer when the encoder fails to start (#5607)
* fix(replay): Release MediaMuxer when the encoder fails to start
The MediaMuxer is opened eagerly in SimpleVideoEncoder's constructor, but
its release() was only reachable on paths that assume start() succeeded.
Two cases leaked it:
- createVideoOf constructed the encoder and called start() in one
expression, so when start() threw the encoder was never assigned and
release() could never run.
- SimpleVideoEncoder.release() released the muxer as the last statement of
the try block, after draining and stopping the codec. Draining a codec
that never started throws, skipping the muxer release.
Release the encoder if start() throws, and always release the muxer from a
finally block so it is freed even when draining/stopping the codec fails.
This surfaced as a CloseGuard "resource was acquired but never released"
warning. Complements #5583.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* changelog
* fix(replay): Skip MediaMuxer stop when no samples were written
MediaMuxer.stop() throws IllegalStateException when the muxer was started
but no sample was ever written to its track. SimpleMp4FrameMuxer.release()
only guarded against the never-started case, so a started-but-empty muxer
made release() throw.
Because release() runs from SimpleVideoEncoder's finally block, that throw
propagates out to createVideoOf, which treats release() as safe cleanup;
the encoder is left dangling and the orphan video file is never deleted.
Only call stop() when at least one sample was written; muxer.release() on a
started-but-not-stopped muxer is safe.
* Format code
* fix(replay): Guard each native release so cleanup never propagates
The finally block in SimpleVideoEncoder.release() released the codec,
surface, and muxer without guards. release() is treated by callers such as
createVideoOf as safe cleanup, but MediaMuxer.stop() (reached via
frameMuxer.release()) can still throw IllegalStateException on a genuine
file-finalization failure even when samples were written. That would skip
the remaining releases and propagate out of release().
Guard each release independently so failing to free one resource neither
skips the others nor escapes to the caller.
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>1 parent 4670d89 commit bbcf99a
6 files changed
Lines changed: 60 additions & 9 deletions
File tree
- sentry-android-replay/src
- main/java/io/sentry/android/replay
- video
- test/java/io/sentry/android/replay
- util
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
166 | 175 | | |
167 | 176 | | |
168 | 177 | | |
| |||
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
71 | | - | |
72 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
| |||
Lines changed: 18 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
| 290 | + | |
295 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
296 | 309 | | |
297 | 310 | | |
298 | 311 | | |
| |||
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
| 61 | + | |
59 | 62 | | |
60 | 63 | | |
61 | 64 | | |
| |||
93 | 96 | | |
94 | 97 | | |
95 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
96 | 119 | | |
97 | 120 | | |
98 | 121 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
| |||
0 commit comments