OneSignal-Xamarin-SDK icon indicating copy to clipboard operation
OneSignal-Xamarin-SDK copied to clipboard

InvalidOperationException in GetTagsAsync

Open ArgusMagnus opened this issue 6 years ago • 2 comments

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+<>c__DisplayClass0_0.<GetTagsAsync>b__0(System.Collections.Generic.Dictionary2[TKey, TValue] tags) TagsHandler.TagsAvailable(Org.Json.JSONObject jsonObject) OneSignal+IGetTagsHandlerInvoker.n_TagsAvailable_Lorg_json_JSONObject_(System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_p0)

ArgusMagnus avatar Dec 17 '18 10:12 ArgusMagnus

@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

Nightsd01 avatar Jan 16 '19 21:01 Nightsd01

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.

ArgusMagnus avatar Jan 29 '19 08:01 ArgusMagnus

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

emawby avatar Apr 18 '23 20:04 emawby

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

ArgusMagnus avatar May 28 '23 07:05 ArgusMagnus