Skip to content

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

@philprime

Description

@philprime

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.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions