Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session Replay is not cleaned up correctly after calling Sentry.close #5069

Open
philprime opened this issue Apr 8, 2025 · 1 comment
Open

Comments

@philprime
Copy link
Contributor

Description

I created a sample in #5055 which provides a function to reload the Sentry SDK:

static func reloadSentrySDK() {
    if SentrySDK.isEnabled {
        print("SentrySDK already started, closing it")
        SentrySDK.close()
    }

    SentrySDK.start { options in
        options.dsn = "https://[email protected]/5428557"
        options.debug = true

        options.tracesSampleRate = 1.0
        options.profilesSampleRate = 1.0
        options.sessionReplay.sessionSampleRate = Self.isSessionReplayEnabled ? 1.0 : 0.0
        options.sessionReplay.enableExperimentalViewRenderer = Self.isExperimentalViewRendererEnabled
    }
}

When closing the SDK the on-demand replay capturing is not restarted.
An initial investigation showed that uninstalling the SentrySessionReplayIntegration calls the method SentrySessionReplay.pause() which invalidates the CADisplayLink used as the trigger for creating frames:

https://github.com/getsentry/sentry-cocoa/blob/0782001b8903e178a3bb8db34f2f366ce1cc04ab/Sources/Sentry/SentrySessionReplayIntegration.m#L523C9-L527

func pause() {
lock.lock()
defer { lock.unlock() }
displayLink.invalidate()
if isFullSession {
prepareSegmentUntil(date: dateProvider.date())
}
isSessionPaused = false
}

When installing the SDK again, there seems to be left-over state and the session replay recorder is not bootstrapped correctly.

When calling stop() instead of pause() in the SentrySessionReplayIntegration, the object gets deallocated and discarded, but it is not started again correctly.

@philprime philprime self-assigned this Apr 8, 2025
@github-project-automation github-project-automation bot moved this to Needs Discussion in Mobile SDKs Apr 8, 2025
@philprime philprime changed the title On-demand Session Replay is not cleaned up correctly after calling Sentry.close Session Replay is not cleaned up correctly after calling Sentry.close Apr 8, 2025
@philprime philprime moved this from Needs Discussion to Todo in Mobile SDKs Apr 9, 2025
@philprime
Copy link
Contributor Author

It looks to me like the change from stop to pause was introduced in #4326 without proper documentation what the difference between the two methods is

@philprime philprime moved this from Todo to In Progress in Mobile SDKs Apr 14, 2025
@kahest kahest added the Platform: Cocoa label Apr 14, 2025 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

No branches or pull requests

3 participants