Or Rapaport
Or Rapaport

Reputation: 71

iOS - Duplicate GET request are sent when switching to background

When switching my app to background / home screen and HTTP GET requests are firing, in some rare cases i can see that the server gets 2 identical request with the same oauth signature and throws an 401 error.

I Create an oauth1 GET request using alamofire 9. Switched to iOS home screen. Returned to the app.

Mostly the Requests are getting cancelled / errored when backgrounded and are sent to the retry interceptor to determine if they should be retried or not.

What happened instead? In most cases it works as expected. but in some random cases, i get 401 unauthorized error from the server that the oauth nonce was already in use. Looking at the server log it seems that there are 2 identical requests that are fired from the app. without reaching to the request interceptor or to the Adapt method for new nonce. It looks like it's the underlaying urlsession that automatically retries GET requests (didn't see it happen for POST / PUT) when switching to background / connection to the server fails at the low level?

I've tried multiple URLSessionConfiguration settings without success. I would like to know if there's a way to stop iOS from sending duplicate GET requests sometimes or if a 401 error can get to the retry interceptor. It goes directly to the failed completion block of the calling function.

Thanks!

Upvotes: 1

Views: 126

Answers (0)

Related Questions