UnobservedTaskException when syncing replica

1091
4
09-07-2018 10:11 AM
JeffSiemens
New Contributor II

I'm getting an UnobservedTaskException "Unable to synchronize replica" when synchronizing a replica (upload edits).

I don't always get the error - only occasionally. I'm using ArcGIS Runtime 100.3 and AGOL hosted feature layers.

at Esri.ArcGISRuntime.Http.ArcGISHttpClientHandler.ArcGISClientHandlerInternal.<SendAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.Http.HttpClient.<FinishSendAsyncUnbuffered>d__59.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Esri.ArcGISRuntime.Internal.RequestRequiredHandler.<IssueRequestAndRespond>d__14.MoveNext()

I'm watching for unobserved task exceptions this way:


TaskScheduler.UnobservedTaskException += (sender, args) =>
{
Logger.Warn($"TaskScheduler.UnobservedTaskException:\n{args.Exception.Message}\n{args.Exception.InnerException?.Message}");
#if DEBUG
DisplayError($"Unobserved task exception: {args.Exception.Message}\n{args.Exception.InnerException?.Message}");
#endif
};

0 Kudos
4 Replies
NathanCastle1
Esri Contributor

Hi Jeff,

Can you please share a code snippet so I can better understand what's going on?

Thanks,

Nathan C.

0 Kudos
dotMorten_esri
Esri Notable Contributor

Are you calling any Task-returning methods without awaiting their result? (ie missing an 'await' - you should see warnings in your build about that)

0 Kudos
JeffSiemens
New Contributor II

I don't believe I'm calling any task returning methods without await their result. 

Below is the code from the view model for a command that is bound to the view using data binding. Note that the code below is 'simplified' so that is sufficiently illustrative of what I'm trying to achieve.

There are no warnings in the build about non-awaited tasks.

I have verified that exceptions are caught by putting a throw new Exception() inside of the second SubmitEditsAsync(Map map), and the error is caught and handled. It looks like the error is occurring outside of the call stack (on a separate thread) in the ArcGIS Runtime.

        private async void SubmitEditsAsync(OfflineArea offlineArea)
        {
            try
            {
                await SubmitEditsAsync(offlineArea.Map);
            }
            catch (Exception e)
            {
                await _dialogHandler.ShowAlertAsync(e);
            }
        }

        private async Task SubmitEditsAsync(Map map)
        {
            // Create the sync task
            var syncTask = await OfflineMapSyncTask.CreateAsync(map);
            syncTask.SyncOfflineMap(new OfflineMapSyncParameters() { SyncDirection = SyncDirection.Upload });

            // Create the job
            var job = syncTask.SyncOfflineMap(new OfflineMapSyncParameters()
            {
                RollbackOnFailure = true,
                SyncDirection = SyncDirection.Upload
            });

            // Await result
            var result = await job.GetResultAsync();
        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
MoreHavoc
New Contributor III

I am also seeing intermittent sync (and initial download) issues.  I am not able to duplicate it reliably as it happens maybe 1 in 10 times when syncing.  I have noticed several observations (these were all tested using UWP 100.3):

  1. I did not initially get any download or sync errors while working on the app, but as the database grew to about 15 tables, and about 1000-2000 records (with attachments making the replica about 32MB) I have started seeing these errors.  
  2. I see the errors on all types of edits: edits on the client only, edits on the server only, edits in both places.
  3. Download and Sync success depends significantly on the version of server.  One of my clients is using 10.4.1 and the sync fails pretty regularly, while my testing in 10.6.1 shows that it only fails about 1 in 10 times.
  4. Sync with ArcGIS Online Hosted Feature Services has never failed for me (although I have not tested it with the same data model I am using with Server)
  5. I get different errors with different versions of server.  With 10.4/10.5 I would get an "Error 500" frequently, which appears to come from the server sometimes and other times the server has no errors in the log and it looks more like runtime just didn't download the database.
  6. With 10.6.1 I have not gotten any server errors, but runtime throws an error that appears to be related to reading/writing to disk.
  7. With 10.6.1, the download error always occurs after (while?) the file is being downloaded, as I am left with a partial database on disk that is far too small and provides a "No Data" error when trying to open it.
  8. When the sync fails, it doesn't usually throw an exception, just has a failed status and some generic error code like 500 or 22.
  9. I am using the Geodatabase Sync task directly, but I have used the Map sync task as well for debugging as it seems to provide more details about specific issues while syncing, if there are any.  It would be great if the Geodatabase sync task returned as detailed a log as the map sync task.

The stack trace I get on a failed download is this:

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  at System.IO.WinRtToNetFxStreamAdapter.<ReadAsyncInternal>d__43.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  at System.IO.BufferedStream.<ReadFromUnderlyingStreamAsync>d__47.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  at Esri.ArcGISRuntime.Internal.FileRequestHelper.<DownloadAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  at Esri.ArcGISRuntime.Internal.FileRequestHelper.<DownloadAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  at Esri.ArcGISRuntime.Internal.RequestRequiredHandler.<IssueRequestAndRespond>d__14.MoveNext()

I have added some code to my app to catch/store these exceptions and the download/sync log entries so that I can begin collecting more data about what is happening during user testing.

0 Kudos