Skip to content

Commit 9bc6a96

Browse files
fix: Stop SessionReplay when closing SDK (#3941)
Call SessionReplay.stop when uninstalling the SDK and invalidate the DisplayLinkWrapper when SessionReplay gets deallocated.
1 parent aba4108 commit 9bc6a96

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Ignore SentryFramesTracker thread sanitizer data races (#3922)
88
- Handle no releaseName in WatchDogTerminationLogic (#3919)
9+
- Stop SessionReplay when closing SDK (#3941)
910

1011
### Improvements
1112

Sources/Sentry/SentrySessionReplay.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ - (void)stop
114114
}
115115
}
116116

117+
- (void)dealloc
118+
{
119+
[self stop];
120+
}
121+
117122
- (void)captureReplayForEvent:(SentryEvent *)event;
118123
{
119124
if (!_isRunning) {

Sources/Sentry/SentrySessionReplayIntegration.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ - (SentryIntegrationOption)integrationOptions
139139

140140
- (void)uninstall
141141
{
142+
[self stop];
142143
}
143144

144145
- (BOOL)shouldReplayFullSession:(CGFloat)rate

Tests/SentryTests/Integrations/SessionReplay/SentrySessionReplayTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,17 @@ class SentrySessionReplayTests: XCTestCase {
208208

209209
expect(Dynamic(sut).isRunning) == false
210210
}
211+
212+
@available(iOS 16.0, tvOS 16, *)
213+
func testDealloc_CallsStop() {
214+
let fixture = startFixture()
215+
func sutIsDeallocatedAfterCallingMe() {
216+
_ = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, errorSampleRate: 1))
217+
}
218+
sutIsDeallocatedAfterCallingMe()
219+
220+
expect(fixture.displayLink.invalidateInvocations.count) == 1
221+
}
211222

212223
func assertFullSession(_ sessionReplay: SentrySessionReplay, expected: Bool) {
213224
expect(Dynamic(sessionReplay).isFullSession) == expected

0 commit comments

Comments
 (0)