fix: Throttle AppSync LimitExceeded errors #67
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
Description of changes:
The LimitExceeded error is received when AppSync throttles the client for making too many subscription requests:
This happens once the rate of subscribes has exceeded the limit on AppSync. Since 100 subscriptions can be established successfully, a loop with 200 or more subscriptions requests will reproduce this.
Consider the current flow
MaxSubscriptionsReachedError(subscriptionId)
(and go into retry logic). But, when sending 101st to 200th subscription requests all at the same time, AppSync throttles this client with errorLimitExceededError
.LimitExceededError
is received, translate this to a genericConnectionProviderError.other
because there's noid
in the response object. SendConnectionProviderError.other
to all 200 subscriptions (even the subscribed ones)..notSubscribed
and return a failed event to the caller. Let's say 100 out of 200 subscriptions are throttled, then all 200 subscriptions will get a callback for each error, which is 20000 callbacks. Even though we removed the listener from the connection provider in the previous PR fix: Subscription failed event should be terminal event #74 , the problem is that connection makes a copy of the subscription listeners before broadcasting the message, so even though they are being removed after sending the error from a previous subscription, they continue to emit a failed message. In normal message rates, removing the connection is enough to do the job.How should we handle
LimitExceededError
?LimitExceededError
withoutid
(w/o subscription id - we'll treat this as a connection level LimitExceededError.). Convert it over to.limitExceeded(nil)
error.Manual testing
When subscribing to 500 subscriptions, 100 are connected successfully, 400 failed events. Send a mutation, 100 subscription events are received.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.