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

Add optional crash reporter #228

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gabrielzanoni
Copy link

What has changed

  • Adds optional crashReporter of type SPTDataLoaderCrashReporter to constructor

Why this was changed

This is an attempt to improve crash logging. It takes into account that the app probably has multiple instances of and SPTDataLoader during its lifecycle, which is why the breadcrumbs are left only in critical spots:

  1. When loads are cancelled
  2. When session gets invalidated
  3. When there's an attempt to make a request in a invalidated session

@gabrielzanoni gabrielzanoni marked this pull request as ready for review February 22, 2023 07:56
completionHandler(disposition, credential);
}

#pragma mark NSURLSessionTaskDelegate

- (void)URLSession:(NSURLSession *)session didBecomeInvalidWithError:(nullable NSError *)error
{
[_invalidatedSessions addObject:session];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an option, we can keep track of invalidated sessions without extra set: a Service owns a SessionSelector, which in turn manages only two (or rather, up to two) session instances, so I guess we could leverage that instead.
Although I'm wondering if a Service should even start performing a request if its only Session has been invalidated. Wdyt?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I'm following why that would be better. This DataLoaderService is the one implementing NSURLSessionTaskDelegate, so if we were to go on that path this service would still have to tell SessionSelector which session is invalidated and then retrieve it after. It seems an unnecessary indirection 🤔 .

About not making a request on an invalidated session, Gianni made a change recently that prevents that from happening on a retry - but we'd still like to know if this happens in a regular request (i.e. leave breadcrumb and crash)

@property (nonatomic, strong) SPTDataLoaderServerTrustPolicy *serverTrustPolicy;
@property (nonatomic, weak, nullable) NSFileManager *fileManager;
@property (nonatomic, weak, nullable) Class dataClass;
@property (nonatomic, strong) NSMutableSet<NSURLSession *> *invalidatedSessions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid to add this complexity in keeping track of what session got invalidated.
The invalidateAndCancel method always invalidates all the sessions handled by the SessionSelector.
My suggestion is to keep only a boolean to keep track of the session invalidation. This will simplify this PR

Comment on lines 503 to 499
} else {
[_crashReporter leaveBreadcrumb:
[NSString stringWithFormat:@"Trying to retry on invalidated sesion. Policy: %ld, Error: %@",
(long)handler.request.backgroundPolicy, error.description]];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this one. The retry is an internal feature of SPTDataLoader. The if at line 402/497 was added to fix a bug where SPTDataLoader was trying to retry on an already invalidated sessions. And to add more on it, entering the else part does not guarantee the session was invalidated, it can just be that single task got cancelled and thus the message could be mis-leading as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this code can't retry on invalidated session anymore, I'll just remove this log then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants