ConnectionProviderError.limitExceeded in SwiftUI app
I'm trying to use Amplify.API.subscribe(request: awsRequest).subscriptionDataPublisher in my SwiftUI view's .onReceive modifier. It works for about a couple minutes and receives messages, but then the subscription dies with the following error firing every second:
Subscription item event failed with error
Caused by:
limitExceeded(Optional("561D67F0-AFA7-49D1-9D23-3C2C0463E09C"))
2022-08-30 11:15:41.423534-0400 Hoops[60527:1978128] ConnectionProviderError.limitExceeded; identifier=E798D82A-6A70-45F2-890B-A2EEBF083039;
I think this is because my SwiftUI views are getting re-rendered several times as expected, but Amplify is counting each render subscription? I also tried using .share() to consolidate requests but issue remains. Any ideas on how to resolve this error?
Thanks for opening this issue @basememara. Can you please provide a code snippet showing how you're using Amplify.API.subscribe(...).subscriptionDataPublisher in .onReceive? SwiftUI view redrawing complexities can cause all sorts of fun bugs like this. I'd like to make sure we understand how you're using it so that we can effectively attempt to reproduce the issue. Thanks!
I get the same error using AWSAppSyncClient.
I create a new subscription in my view controller's viewDidLoad, something like:
override func viewDidLoad() {
super.viewDidLoad()
self.onCreateSub = try? AWSAppSyncClient.defaultClient.subscribe(subscription: MySubscription(), queue: .apiQueue) { result, transaction, error in
...
}
}
I then navigate to this view controller and back about 20 times, after that subscription stops working. I'd expect the subscription to properly cancel every time the view controller deallocates.
Update:
The problem only happens if I reuse the same instance of AWSAppSyncClient. It goes away if I create a new instance for every subscription.
Hi @almasios, It's failing with the same error most likely because both AWSAppSyncClient and Amplify.API use the same AppSync subscription code, so it's cycling through the same code paths.
I'd expect the subscription to properly cancel every time the view controller deallocates.
Are you able to call unsubscribe when the view deallocates to test out the theory of the bug (this can also be the workaround if this is a bug)? We should reproduce this in the viewDidLoad and SwiftUI's .onReceive with verbose logging, Amplify.Logging.logLevel = .verbose to see what's happening and understand which "limitExceeded" this is, it may be the issue for too many connections in a short time window, or that it has reached the 100 subscription connection limit per client.
Closing this issue due to no activity. Feel free to reach us back if the above suggestion does not work for you.