Skip to content

Commit

Permalink
fix: Session replay crash when writing the replay (#4186)
Browse files Browse the repository at this point in the history
* fix: Session replay crash when writing the replay

* Update CHANGELOG.md
  • Loading branch information
brustolin authored Jul 22, 2024
1 parent f1b97be commit 10f96ae
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Session replay crash when writing the replay (#4186)

## 8.31.1

### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ private struct VideoFrames {

enum SentryOnDemandReplayError: Error {
case cantReadVideoSize
case assetWriterNotReady
}

@objcMembers
Expand Down Expand Up @@ -120,7 +121,11 @@ class SentryOnDemandReplay: NSObject, SentryReplayVideoMaker {
videoWriter.startSession(atSourceTime: .zero)

videoWriterInput.requestMediaDataWhenReady(on: workingQueue.queue) { [weak self] in
guard let self = self else { return }
guard let self = self, videoWriter.status == .writing else {
videoWriter.cancelWriting()
completion(nil, SentryOnDemandReplayError.assetWriterNotReady)
return
}

if frameCount < videoFrames.framesPaths.count {
let imagePath = videoFrames.framesPaths[frameCount]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,26 @@ class SentryOnDemandReplayTests: XCTestCase {
XCTAssertEqual(sut.frames.count, 0)
}

func testInvalidWriter() {
let queue = SentryDispatchQueueWrapper()
let sut = SentryOnDemandReplay(outputPath: outputPath.path,
workingQueue: queue,
dateProvider: dateProvider)
let expect = expectation(description: "Video render")

let start = dateProvider.date()
sut.addFrameAsync(image: UIImage.add)
dateProvider.advance(by: 1)
let end = dateProvider.date()

try? sut.createVideoWith(beginning: start, end: end, outputFileURL: URL(fileURLWithPath: "/invalidPath/video.mp3")) { _, error in
XCTAssertNotNil(error)
XCTAssertEqual(error as? SentryOnDemandReplayError, SentryOnDemandReplayError.assetWriterNotReady)
expect.fulfill()
}

wait(for: [expect], timeout: 1)
}

}
#endif

0 comments on commit 10f96ae

Please sign in to comment.