SIGSEV in Asynchronous Tasks on Xamarin Android

In our current Xamarin Android project, we see a lot of SIGSEGV in mono-rt for our async tasks. Below is one such code example that generates about 20% SIGSEGV. It looks like I'm doing something fundamentally wrong here, or there is a major issue with Xamarin for Android. Can someone help me point out what is wrong with this code that generates this SIGSEGV?

Is this related to https://bugzilla.xamarin.com/show_bug.cgi?id=13707 ?

EDIT: I can see this behavior throughout the application now. Here is the log file that has other errors. All failures occur in the asynchronous code of the task. Something is wrong here. Any help is appreciated.

public async Task GetDataAsync(string downloadUri) {
    using (WebClient downloader = new WebClient ()) {
        downloader.Headers.Add ("x-bz-appId", "android");
        downloader.Headers.Add ("x-bz-authToken", Comman.AuthToken);
        downloader.Headers.Add(HttpRequestHeader.ContentType, "application/json");

        var t = await downloader.DownloadStringTaskAsync(new Uri(downloadUri)).ContinueWith(downloadTask => {
            if (downloadTask.Status == TaskStatus.RanToCompletion) {
                JObject response = null;
                response = JObject.Parse(downloadTask.Result);
                return response;
            } else {
                if (downloadTask.Exception != null) {
                    throw downloadTask.Exception;
                } else {
                    throw new Exception(downloadTask.Status.ToString());
                }
            }
        });
        return t;
    }
}

      


[mono-rt] Stacktrace:
[mono-rt] 
[mono-rt]   at  <0xffffffff>
[mono-rt]   at (wrapper managed-to-native) object.__icall_wrapper_mono_array_new_specific (intptr,int) 
[mono-rt]   at System.Array.Resize (T[]&,int) 
[mono-rt]   at System.Collections.Generic.List`1.set_Capacity (int) 
[mono-rt]   at System.Collections.Generic.List`1.GrowIfNeeded (int) 
[mono-rt]   at System.Collections.Generic.List`1.Insert (int,T) 
[mono-rt]   at Newtonsoft.Json.Linq.JContainer.InsertItem (int,Newtonsoft.Json.Linq.JToken,bool) 
[mono-rt]   at Newtonsoft.Json.Linq.JProperty.InsertItem (int,Newtonsoft.Json.Linq.JToken,bool) 
[mono-rt]   at Newtonsoft.Json.Linq.JContainer.AddInternal (int,object,bool) 
[mono-rt]   at Newtonsoft.Json.Linq.JContainer.Add (object) 
[mono-rt]   at Newtonsoft.Json.Linq.JContainer.ReadContentFrom (Newtonsoft.Json.JsonReader) 
[mono-rt]   at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom (Newtonsoft.Json.JsonReader) 
[mono-rt]   at Newtonsoft.Json.Linq.JObject.Load (Newtonsoft.Json.JsonReader) 
[mono-rt]   at Newtonsoft.Json.Linq.JObject.Parse (string) 
[mono-rt]   at Bloomz.Core.APIClient/c__async0/c__AnonStorey56.<>m__0 (System.Threading.Tasks.Task`1) [0x0004a] in /Users/hponnu/Projects/bloomz.native.android.2/Bloomz.Core/HelperClass/APIClient.cs:122
[mono-rt]   at System.Threading.Tasks.TaskActionInvoker/FuncTaskInvoke`2.Invoke (System.Threading.Tasks.Task,object,System.Threading.Tasks.Task) 
[mono-rt]   at System.Threading.Tasks.Task.InnerInvoke () 
[mono-rt]   at System.Threading.Tasks.Task.ThreadStart () 
[mono-rt]   at System.Threading.Tasks.Task.Execute () 
[mono-rt]   at System.Threading.Tasks.TaskScheduler.TryExecuteTask (System.Threading.Tasks.Task) 
[mono-rt]   at System.Threading.Tasks.SynchronizationContextScheduler.TaskLaunchWrapper (object) 
[mono-rt]   at Android.App.SyncContext/c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/1131/2a7b6821/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:18
[mono-rt]   at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/1131/2a7b6821/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
[mono-rt]   at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/1131/2a7b6821/source/monodroid/src/Mono.Android/platforms/android-12/src/generated/Java.Lang.IRunnable.cs:71
[mono-rt]   at (wrapper dynamic-method) object.18db936a-f8a6-4eb0-838d-1159fbb9846c (intptr,intptr) 
[mono-rt]   at (wrapper native-to-managed) object.18db936a-f8a6-4eb0-838d-1159fbb9846c (intptr,intptr) 
[mono-rt] 
[mono-rt] =================================================================
[mono-rt] Got a SIGSEGV while executing native code. This usually indicates
[mono-rt] a fatal error in the mono runtime or one of the native libraries 
[mono-rt] used by your application.
[mono-rt] =================================================================
[mono-rt]

      

+3


source to share


1 answer


Okay for starters, try refactoring your code so that it uses the async syntax correctly, then you can probably see where your exception is coming from. It seems that what you tried to do:

public async Task<JToken> GetDataAsync(string downloadUri) {
    using (WebClient downloader = new WebClient ()) {
        downloader.Headers.Add ("x-bz-appId", "android");
        downloader.Headers.Add ("x-bz-authToken", Comman.AuthToken);
        downloader.Headers.Add(HttpRequestHeader.ContentType, "application/json");

        string unParsedResponse = null;
        try{
            unParsedResponse = await downloader.DownloadStringTaskAsync(new Uri(downloadUri));
        }
        cath(Exception ex){
            throw;
        }
        JObject response = null;
        response = JObject.Parse(unParsedResponse);
        return response;
    }
}

      



PS you don't really need a try-catch block, because waiting for the task will catch any exception on it, and since you don't really do anything other than throwing it, the try catch is useless here.

Hope it helps.

+1


source







All Articles