-
Notifications
You must be signed in to change notification settings - Fork 263
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
[Fix] Handle incorrect 404
, delay making requests to new IDs
#1470
Conversation
fb762a5
to
03ab84b
Compare
404
s, delay making requests to new IDs
404
s, delay making requests to new IDs404
, delay making requests to new IDs
03ab84b
to
4390d1b
Compare
* This rule `opening_brace` declares opening braces should be on the same line as the declaration * However for multiline if / let statements, it makes it harder to read: if let blah = blah, let foo = blah.foo { // do something, less readable } if let blah = blah, let foo = blah.foo { // do something, more readable } * See linked PR for an upcoming option, so we can re-enable this rule
* This is a new behavior which waits a specific amount of time after something is created (such as a User or Subscription) before making a network call to get or update it. * The main motivation is that the OneSignal's server may return a 404 if you attempt to GET or PATCH on something that was just created. This is due fact that OneSignal's backend server replication sometimes has a delay under load. This may be considered a bug in the backend, but the SDK has a responsibility to handle this case as well. Additional Details: * User Manager owns an instance of OSNewRecordsState * Requests will check their records within the `prepareForExecution()` check
* Push subscription IDs and onesignal IDs can be added to the new records storage after they are created * Requests can be delayed by a specific “cool down” period plus a small buffer - they are flushed after a delay when they need to wait for the "cool down" period to access a user or subscription after its creation. * Anytime `prepareForExecution()` fails, the executor will put a delayed task to flush the requests again again after a specific delay. * In CreateUser, new IDs will only be added to the new records storage if the Creates were truly Creates, and not “faux” Creates meant to get an onesignal ID for a given external ID. This latter case happens after a 409 Identify conflict, meaning the user definitely exists and the Onesignal ID will not be new. * In IdentifyUser successful, the executor adds onesignal ID to new records again because an immediate fetch for hydration may not return the newly-applied external ID. We will encounter a problem with hydration in this case. * User fetch will always be called after a delay unless it is to refresh the user state on a new session. This is because a fetch that is not on a new session is always for getting user data after a create or identify. * Nits: Also moved some opening braces to new lines for improved readability of multi-line “if / let / guard” statements
* Executors init take in additional argument * A failing test needs more time to complete
4390d1b
to
80d940f
Compare
iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSNewRecordsState.swift
Outdated
Show resolved
Hide resolved
iOS_SDK/OneSignalSDK/OneSignalUser/Source/Requests/OSRequestAddAliases.swift
Show resolved
Hide resolved
997e548
to
c6db876
Compare
* The canAccess method should really check a non-optional string * Adjust the use of this method at the calling site
c6db876
to
529a148
Compare
Badge test started failing this week, but can look at later. It looks like the runner-image has changed, and the new tests are run on ios 18.1. Previous passing runner image used:
Failing runner image used:
|
Description
One Line Summary
Handle incorrect 404 responses from the OneSignal's backend by adding a delay after creates, when new subscription IDs or OneSignal IDs can be created on the backend.
Details
See Android Implementation here
Backend Issue
OneSignal sometimes returns a
404
onGET
andPATCH
requests if you are accessing something immediately after it was created. Normally the OneSignal backend can accept fetch/updates right way, but it all depends on it's server load and replication process. There isn't a guaranteed amount of time a client can wait, so SDKs has to work around this problem.SDK's work around strategy
Add a minimum delay after creating records (User or Subscription) before allowing any requests to fetch or update that specific record, based on the
onesignalId
orsubscriptionId
.Motivation
404/410 responses are being handled by recreating the missing record (User or Subscription), however this isn't always the right way to handle these, give the backend caveat noted above. Recreating these records can create side-effects and extra load we want to avoid.
Scope
Add a delay processing user-based or subscription-based requests.
Future Considerations
Testing
Unit testing
🚧 New unit tests are WIP
Manual testing
Physical iPhone 13 on iOS 17.4
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is