Commit 409085b
committed
fix(display): close the video writer when the audio writer's close throws
recordScreenAndAudioToFiles closed its two writers in sequence:
audioWritten = await audioOut.close();
await videoOut.close();
M4aFileWriter finalizes by appending the moov box, ending the stream, then
reopening the finished file to patch mdat's length field. Any of those can fail
on a full disk or a reaped temp directory, long after every frame is already
safely on disk. When one does, the video writer's close is skipped.
The cost is a leaked file descriptor. Without close() the write stream is never
ended, and Node does not release descriptors on garbage collection, so it lives
until the process exits. The error the stream is holding also goes unread, since
AnnexBFileWriter only surfaces that from write() or close().
The video file itself is intact. Node's write queue drains on its own once
chunks are handed to write(), the recording loop awaits every write, and Annex-B
is an elementary stream with no index or footer to finalize, so a file ending
after the last frame is valid and playable. Verified by writing 15 MB and never
calling close(): every byte was on disk.
Closing the video writer from a finally makes it independent of the audio
writer's failure. The audio error still propagates when the video close
succeeds. If both throw the video error supersedes, which is standard finally
behaviour and an acceptable edge for a path that has already failed.
Covered by a unit test that stubs the audio writer's close to throw and asserts
the video writer was still closed. Reverting to sequential closes fails it with
0 closes instead of 1.1 parent 0bc93d0 commit 409085b
2 files changed
Lines changed: 70 additions & 3 deletions
File tree
- src/services/ios/display/recording
- test/unit/display/recording
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
199 | | - | |
200 | | - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
201 | 209 | | |
202 | 210 | | |
203 | 211 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
9 | 14 | | |
10 | 15 | | |
11 | 16 | | |
| |||
60 | 65 | | |
61 | 66 | | |
62 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
63 | 122 | | |
0 commit comments