2014-09-16 3 views
3

Dans notre projet Xamarin actuel pour Android, nous voyons beaucoup de SIGSEGV dans le mono-rt pour nos tâches asynchrones. Voici un exemple de code qui génère environ 20% de fois SIGSEGV. On dirait que je fais quelque chose de fondamentalement faux ici ou il y a un problème sérieux avec Xamarin pour Android. Quelqu'un peut-il m'aider à signaler ce qui ne va pas avec ce code qui génère ce SIGSEGV?SIGSEV en tâches asynchrones sur Xamarin Android

Est-ce lié à https://bugzilla.xamarin.com/show_bug.cgi?id=13707?

EDIT: Je vois ce genre de comportement partout dans l'application maintenant. Voici un log file qui a d'autres erreurs. Tous les accidents se produisent sur le code de tâche asynchrone. Quelque chose ne va vraiment pas ici. Toute aide est appréciée.

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] 
+0

Essayez-vous de courir sur le genymotion? – alexandrius

+0

Oui, mais je vois les mêmes problèmes sur le téléphone aussi. Sur Genymotion, cela se produit à une fréquence plus élevée. – ponnu

+0

Est-ce que vous obtenez le résultat de 'downloadTask' (downloadTask.Result)? Est-ce que l'exception survient avant cela? –

Répondre

1

Eh bien pour commencer essayer de factoriser votre code afin qu'il utilise correctement la syntaxe async, alors vous verrez probablement où votre exception est originaire de. Il semble que ce que vous essayez de faire était:

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; 
    } 
} 

post-scriptum vous n'avez vraiment pas besoin du bloc try-catch car attendre une tâche intercepte n'importe quelle exception et comme vous ne faites rien d'autre que de le lancer, le try try est futile ici.

Espérons que ça aide.

+0

Donc vous suggérez que je fais "TaskScheduler.FromCurrentSynchronizationContext()" sur le ContinueWith. J'ai essayé cela, la fréquence des accidents a diminué mais je les ai toujours. BTW "downloadTask" n'est pas défini dans votre exemple de code! – ponnu

+0

Non, je vous suggère soit d'utiliser la syntaxe async soit de gérer manuellement les tâches avec 'ContinueWith()', de retourner la tâche, de vérifier son statut, les exceptions, etc. Dans votre exemple, vous faites les deux qui sont mal et potentiellement cause de vos exceptions. –

Questions connexes