Skip to content

Commit

Permalink
Fix: Thread running at User-initiated quality-of-service for Session …
Browse files Browse the repository at this point in the history
…replay (#4439)

AVFoundation video maker runs on a lower QoS than user-initiated processes, and the thread sanitizer complains about waiting for it on a higher-level thread. We are changing the QoS of our call to create video.
  • Loading branch information
brustolin authored Oct 15, 2024
1 parent f31b069 commit dfde71c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ via the option `swizzleClassNameExclude`.
- Finish TTID correctly when viewWillAppear is skipped (#4417)
- Swizzling RootUIViewController if ignored by `swizzleClassNameExclude` (#4407)
- Data race in SentrySwizzleInfo.originalCalled (#4434)
- Thread running at user-initiated quality-of-service for session replay (#4439)


### Improvements
Expand Down
8 changes: 7 additions & 1 deletion Sources/Sentry/SentrySessionReplayIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ - (void)startWithOptions:(SentryReplayOptions *)replayOptions
= (NSInteger)(shouldReplayFullSession ? replayOptions.sessionSegmentDuration + 1
: replayOptions.errorReplayDuration + 1);

dispatch_queue_attr_t attributes = dispatch_queue_attr_make_with_qos_class(
DISPATCH_QUEUE_SERIAL, DISPATCH_QUEUE_PRIORITY_LOW, 0);
SentryDispatchQueueWrapper *dispatchQueue =
[[SentryDispatchQueueWrapper alloc] initWithName:"io.sentry.session-replay"
attributes:attributes];

self.sessionReplay = [[SentrySessionReplay alloc]
initWithReplayOptions:replayOptions
replayFolderPath:docs
Expand All @@ -290,7 +296,7 @@ - (void)startWithOptions:(SentryReplayOptions *)replayOptions
touchTracker:_touchTracker
dateProvider:SentryDependencyContainer.sharedInstance.dateProvider
delegate:self
dispatchQueue:[[SentryDispatchQueueWrapper alloc] init]
dispatchQueue:dispatchQueue
displayLinkWrapper:[[SentryDisplayLinkWrapper alloc] init]];

[self.sessionReplay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class SentrySessionReplayTests: XCTestCase {
private class TestReplayMaker: NSObject, SentryReplayVideoMaker {
var screens = [String]()

var createVideoCallBack: ((SentryVideoInfo) -> Void)?

struct CreateVideoCall {
var beginning: Date
var end: Date
Expand All @@ -30,6 +32,7 @@ class SentrySessionReplayTests: XCTestCase {
try? "Video Data".write(to: outputFileURL, atomically: true, encoding: .utf8)
let videoInfo = SentryVideoInfo(path: outputFileURL, height: 1_024, width: 480, duration: end.timeIntervalSince(beginning), frameCount: 5, frameRate: 1, start: beginning, end: end, fileSize: 10, screens: screens)

createVideoCallBack?(videoInfo)
return [videoInfo]
}

Expand Down Expand Up @@ -63,7 +66,7 @@ class SentrySessionReplayTests: XCTestCase {
var lastReplayId: SentryId?
var currentScreen: String?

func getSut(options: SentryReplayOptions = .init(sessionSampleRate: 0, onErrorSampleRate: 0) ) -> SentrySessionReplay {
func getSut(options: SentryReplayOptions = .init(sessionSampleRate: 0, onErrorSampleRate: 0), dispatchQueue: SentryDispatchQueueWrapper = TestSentryDispatchQueueWrapper() ) -> SentrySessionReplay {
return SentrySessionReplay(replayOptions: options,
replayFolderPath: cacheFolder,
screenshotProvider: screenshotProvider,
Expand All @@ -72,7 +75,7 @@ class SentrySessionReplayTests: XCTestCase {
touchTracker: SentryTouchTracker(dateProvider: dateProvider, scale: 0),
dateProvider: dateProvider,
delegate: self,
dispatchQueue: TestSentryDispatchQueueWrapper(),
dispatchQueue: dispatchQueue,
displayLinkWrapper: displayLink)
}

Expand Down Expand Up @@ -147,7 +150,7 @@ class SentrySessionReplayTests: XCTestCase {
XCTAssertNotNil(fixture.lastReplayRecording)
assertFullSession(sut, expected: true)
}

func testReplayScreenNames() throws {
let fixture = Fixture()
let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, onErrorSampleRate: 1))
Expand Down

0 comments on commit dfde71c

Please sign in to comment.