Bug 51580 - AsyncManager.Run is deadlocking when invoking AndroidDesignerSession.DisposeAsync
Summary: AsyncManager.Run is deadlocking when invoking AndroidDesignerSession.DisposeA...
Status: VERIFIED FIXED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Android ()
Version: 4.3.0 (C9)
Hardware: PC Windows
: High normal
Target Milestone: 4.3.0 (C9)
Assignee: Bugzilla
URL:
Depends on: 49846
Blocks:
  Show dependency tree
 
Reported: 2017-01-17 19:18 UTC by Alan McGovern
Modified: 2017-02-07 10:11 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Alan McGovern 2017-01-17 19:18:19 UTC
I triggered some deadlocks and uploaded the memory dumps while looking into https://bugzilla.xamarin.com/show_bug.cgi?id=46874 for the VS team. The deadlocks I triggered were unrelated to the original bug, so I'm just refiling it here to be dealt with eventually:

--- One comment

I uploaded the memory dumps and the issue was confirmed to be not related to the designer itself (so far). The problem is believed to be the CompleteOnCurrentThread invocation:

> Microsoft.VisualStudio.Threading.dll!Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread() Line 839
> Merq.Async.Core.dll!Merq.AsyncManager.Run(System.Func<System.Threading.Tasks.Task> asyncMethod)
> Xamarin.VisualStudio.Android.dll!Xamarin.VisualStudio.Android.MonoAndroidDesignerPane.DisposeSession()


Reassigning this to General for now as there is still nothing actionable from our side. If there are issues with the designer they'd probably be best filed as a new bug with the relevant stacktraces/dumps attached so we can deal with them. We can use this bug to deal with the AsyncManager usage issues.

---

--- Second relevant comment ---
The deadlock this bug is dealing with was mitigated by changing `AsyncManager.Run` to `AsyncManager.RunAsync` as part of this commit, https://github.com/xamarin/XamarinVS/commit/f18ef199b768479ba936908ba82d24b9ade032b1, however the usage of `AsyncManager.RunAsync` is incorrect and can lead to deadlocks.
---
Comment 1 Alan McGovern 2017-01-17 19:23:55 UTC
This is the same as bug #49846, but the patch applied to close that bug appears to violate some of the VS threading rules and so can lead to deadlocks. Leaving this bug open until we can deal with it properly.
Comment 2 Jose Gallardo 2017-01-18 15:00:14 UTC
As the intent of this bug is to deal with the AsyncManager usage issues, I'm updating the target milestone to C10, so we can keep tracking of any potential fixes around it, if needed.
Comment 3 Alan McGovern 2017-01-18 16:28:27 UTC
The AsyncManager usage was removed in the cases where we have found it deadlocking. The main reason for the removal is that the calls were unnecessary. The secondary reason is that it is not safe to wrap arbitrary code with `AsyncManager.Run` invocations due to the restrictions imposed by the underlying JoinableTaskFactory.Run. It can cause correct asynchronous code to deadlock the IDE.

master: https://github.com/xamarin/XamarinVS/commit/5a1348fd23056863b36f0b781bc1c50a0129fb52

cycle9: https://github.com/xamarin/XamarinVS/commit/5a1348fd23056863b36f0b781bc1c50a0129fb52
Comment 4 Shruti 2017-02-07 08:19:02 UTC
Hey @Alan,

We are not sure about the steps which will help us to reproduce this issue.

It would be great If you give your valuable response which would help us to reproduce/verify this issue
Comment 5 Alan McGovern 2017-02-07 09:59:14 UTC
Unfortunately it's a random deadlock.
Comment 6 Alan McGovern 2017-02-07 09:59:33 UTC
However since the code doesn't exist now we know the deadlock also doesn't exist.
Comment 7 Shruti 2017-02-07 10:11:53 UTC
Great Thanks @Alan for quick respond.


Closing this issue as per comment6