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

Investigate abnormal sessions on iOS #2169

Open
buenaflor opened this issue Jul 15, 2024 · 7 comments
Open

Investigate abnormal sessions on iOS #2169

buenaflor opened this issue Jul 15, 2024 · 7 comments

Comments

@buenaflor
Copy link
Contributor

buenaflor commented Jul 15, 2024

Description

There seems to be a disproportionate amount of abnormal sessions on iOS on certain users compared to Android

Read more about abnormal sessions here

Info

https://github.com/getsentry/sentry-cocoa/blob/e773cad622b86735f1673368414009475e4119fd/Sources/Sentry/SentryHub.m#L177

https://github.com/getsentry/sentry-cocoa/blob/main/Sources/Sentry/SentrySessionTracker.m#L119

This is the code path for setting abnormal sessions.

I can reproduce it by forcibly killing the app through the IDE but I'm struggling to reproduce it from a user's perspective purely through the simulator.

essentially if this is null:

    NSDate *_Nullable lastInForeground =
        [[[hub getClient] fileManager] readTimestampLastInForeground];

Then ios sets it as an abnormal session

@denrase
Copy link
Collaborator

denrase commented Aug 6, 2024

@buenaflor Seems to work to me as intended. Was suspecting that willResignActive was not always called, but we are using it correctly with the notification. https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622950-applicationwillresignactive

How large is the gap between iOS/Android? Users on iOS tend to kill apps periodically in multitasking, maybe this could have a negative impact?

@denrase
Copy link
Collaborator

denrase commented Sep 2, 2024

When is last in foreground written?

Tried again when the last in foreground timestamp is written.

  • Phone is locked
  • Entering multitasking
  • Going to the home screen

In all cases, the UIApplicationWillResignActiveNotification is received by the SDK and we set the timestamp. So this is correct.

Killing the app in multitasking

When going to multitasking willResignActive is called. After killing the app, willTerminate is called. Which ends the current session and deletes the current timestamp.

/**
 * We always end the session when the app is terminated.
 */
- (void)willTerminate
{
    NSDate *sessionEnded = nil == self.lastInForeground
        ? [SentryDependencyContainer.sharedInstance.dateProvider date]
        : self.lastInForeground;
    SentryHub *hub = [SentrySDK currentHub];
    [hub endSessionWithTimestamp:sessionEnded];
    [[[hub getClient] fileManager] deleteTimestampLastInForeground];
    self.wasDidBecomeActiveCalled = NO;
}

So when restarting we do not have a timestamp, but also no session. This is correct.

Per Apples documentation, we have about 5 seconds to do some final cleanup here. Only issue I could see is we manage to delete the timestamp, but not the session, wich seems very unlikely, as we delete the timestamp after the session.

@denrase
Copy link
Collaborator

denrase commented Sep 2, 2024

@buenaflor Tried again and checked apple docs, but i don't see a normal user path wehre this might happen. So I just put this in 'Needs More Information'. Do we have some instances with breadcrumbs so we could figure out if this is an issue?

If not, i'd suggest closing this and re-opening when this gets reported again. WDYT?

@buenaflor
Copy link
Contributor Author

This might happen because of errors originating from platform-specific code, for example SocketException when using http libraries

@buenaflor
Copy link
Contributor Author

haven't found much info whether it happens on http or dio but I don't think it would affect the result, best to check both

@denrase
Copy link
Collaborator

denrase commented Sep 17, 2024

@buenaflor I tried both dio and http with our sample app an network link conditioner set to 100% loss, but could not provoke any abnormal sessions.

@denrase
Copy link
Collaborator

denrase commented Oct 8, 2024

Works as expected when provoking a crash on the plugin side. The session is detected as crashed on the next start, the cached session deleted, crash reported.

@denrase denrase removed their assignment Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs More Information
Development

No branches or pull requests

2 participants