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

Should NetworkDataResourceService call session.invalidateAndCancel() on deinit? #70

Open
bizz84 opened this issue Jan 30, 2018 · 1 comment

Comments

@bizz84
Copy link

bizz84 commented Jan 30, 2018

Use Case

My client creates a secure session which is configured for certificate pinning.

When the app starts, I create a new session like so:

URLSession(configuration: .default, delegate: self, delegateQueue: nil)

This is then passed on to all the network services in the app.

Internally, each service creates a new NetworkDataResourceService.

The problem is that once a network service is no longer needed, it is deallocated and with it it brings down the NetworkDataResourceService, which calls session.invalidateAndCancel().

Later, when I create a new network service and try to make a request, the app crashes because I'm trying to use an invalid session.

Discussion

It appears that NetworkDataResourceService takes full ownership of the session. Is this the right thing to do?

I could inject a single NetworkDataResourceService everywhere in the app, and this would guarantee that the session is not invalidated.

If this is the suggested approach, I would like NetworkDataResourceService to conform to a protocol, so I can stub it out in my tests. For the time being, I can just subclass.

@neilkimmett
Copy link

I agree, invalidating the session seems like an unreasonably destructive action to take here, but I may be missing some context about why its needed.

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

No branches or pull requests

2 participants