OneSignal / OneSignal-Xamarin-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Xamarin app with OneSignal. https://onesignal.com
Other
105 stars 50 forks source link

InvalidOperationException in GetTagsAsync #126

Closed ArgusMagnus closed 1 year ago

ArgusMagnus commented 5 years ago

Some times a InvalidOperationException is thrown in GetTagsAsync (confirmed on Android). The cause is likely, that the callback passed to GetTags is called more than once under some circumstances and thus TaskCompletionSource.SetResult throws. Easiest fix would be to change @this.GetTags(tags => tcs.SetResult(tags)); to @this.GetTags(tags => tcs.TrySetResult(tags)); although I don't know why the callback is called more than once in the first place, there might be an underlying issue.

Stack Trace: TaskCompletionSource1[TResult].SetResult(TResult result) OneSignalExtensions+<>cDisplayClass0_0.b__0(System.Collections.Generic.Dictionary2[TKey, TValue] tags) TagsHandler.TagsAvailable(Org.Json.JSONObject jsonObject) OneSignal+IGetTagsHandlerInvoker.n_TagsAvailable_Lorg_jsonJSONObject(System.IntPtr jnienv, System.IntPtr nativethis, System.IntPtr native_p0)

Nightsd01 commented 5 years ago

@ArgusMagnus This is definitely a bug we will be fixing - however - I would also recommend that you look at how often you are calling GetTags and make sure you are not calling it too frequently. This bug is only apparent if you call GetTags often enough to where the previous request still hasn't finished.

We will be creating a PR in our Android SDK and will be releasing an update soon

ArgusMagnus commented 5 years ago

On further thought, this might be more serious than I thought. One handler getting called twice probably means that another one is not called at all, which can lead to indefinite waiting, which likely is a serious problem, especially if you are using async-await.

emawby commented 1 year ago

Hello this issue has been open for a very long time with no activity is it still a problem?

ArgusMagnus commented 1 year ago

Im no longer using OneSignal in my project, I don't know if it's still a problem.