Closed makadev closed 2 years ago
Hi @makadev, thanks for the report.
I am currently checking with the backend team, if there is a way to reliably mitigate this by e.g. sending some kind of identifier along with a request/event that can be used to unique them on server side. But I am not sure if that's possible yet, or will be possible in the near term.
In the meantime I think we should either update the documentation, or fix #311. What do you think?
Hi @brototyp, thanks for the answer.
In the meantime I think we should either update the documentation, or fix #311. What do you think?
Maybe both.
I'm cautious about the proposed solution from #311 since I never used Background Sessions but from what I read it might work by creating a custom Dispatcher like an URLSessionDispatcher variant using Background Sessions and let the user decide, which dispatcher is to be used.
That sounds like a great idea.
Let's update the documentation asap as a short term "solution"
Create a dispatcher that uses a background session to dispatch events
TBD: Is there ever a reason not to use the background-session dispatcher? Should we let the user of the SDK decide which dispatcher to use, or just provide a single one?
Another approach could be to create a background task before sending the request and finishing it after the response is processed. This is the way the Google Analytics SDK did solve it back in the days.
Hi @makadev, I just created this PR. My approach there is to wrap every sending of the events into a background task. Can you try it out and give me some feedback?
Hi @brototyp,
I've tested it with the dispatch
in applicationDidEnterBackground
and the BackgroundDispatcher
is working as expected. The POST
is handled in background and there are no more bogus connection issues and duplicates. 👍
If dispatch is being used as documented under Manual dispatching, it might send the same events again.
As mentioned in #311, the connection is being closed with a TimeOut Error when the App enters Background. But in difference to a real Connection or Send TimeOut the request will be send and handled by the remote server.
I could reproduce the Problem with MatomoTracker 7.2.0 on iOS 13.2.2 and iOS 12.4.x as follows:
Trigger one or more event's which do not hit the Time or Event count limit for dispatching and put the App in Background.
When
applicationDidEnterBackground
call'sdispatch
all queued events will be send but the connection fails:The localized error "Zeitüberschreitung bei der Anforderung." means that the request timed out.
Next time the App is opened, dispatch will send everything again:
Check Server logs (and Tracker), it shows both requests from step 2./3. where handled:
--
Only mitigation I see is to not use manual dispatching at points, where the app enters background f.e. in
applicationDidEnterBackground
or when opening external apps. Note that the Problem still exists without manual dispatching, not very likely to be triggered but it's possible.