android: App crashes with debugger attached but only sometimes
I am sorry for not following the issue template, but couldn’t get my mind around that with this current problem.
After updating Android’s Support Libraries (v28.0+) to get targeted with monoandroid90, the app crashes sometimes with the stack trace I provided bellow. If there are breakpoints active this won’t happen.
Different versions of Xamarin.Android were tested, the current one I’m using is the latest 9.4.1.0 that comes with the default vs19. I was not able to reproduce this on a fresh install of the vs17 with the default XA that comes with it (9.1.7.0)
Using versions Visual Studio 2019 v16.2 or 16.2.1 Xamarin 16.2.0.91 Xamarin.Android.SDK 9.4.1.0
The following stack trace shows the current problem I’m facing.
First thing that strike the eyes is that “Thread Pool Worker”. No settings for thread pools were changed, we’re running defaults.
"Thread Pool Worker" at <unknown> <0xffffffff>
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () <0x00007>
at (wrapper runtime-invoke) <Module>.runtime_invoke_bool (object,intptr,intptr,intptr) [0x0002b] in <ff07eae8184a40a08e79049bbcb31a0e>:0
"Finalizer"08-06 16:26:25.748 E/mono (11487): Full thread dump:
"Thread Pool Worker" at <unknown> <0xffffffff>
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () <0x00007>
at (wrapper runtime-invoke) <Module>.runtime_invoke_bool (object,intptr,intptr,intptr) [0x0002b] in <ff07eae8184a40a08e79049bbcb31a0e>:0
"Debugger agent"
"Timer-Scheduler" at <unknown> <0xffffffff>
at (wrapper managed-to-native) System.Threading.WaitHandle.Wait_internal (intptr*,int,bool,int) <0x00007>
at System.Threading.WaitHandle.WaitOneNative (System.Runtime.InteropServices.SafeHandle,uint,bool,bool) [0x0001f] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.WaitHandle.InternalWaitOne (System.Runtime.InteropServices.SafeHandle,long,bool,bool) [0x00019] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.WaitHandle.WaitOne (long,bool) [0x00010] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.WaitHandle.WaitOne (int,bool) [0x0001d] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.WaitHandle.WaitOne (int) [0x00003] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.Timer/Scheduler.SchedulerThread () [0x00043] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.ThreadHelper.ThreadStart_Context (object) [0x0001f] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) [0x00073] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) [0x00004] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object) [0x0002f] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.ThreadHelper.ThreadStart () [0x00014] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) [0x00067] in <ff07eae8184a40a08e79049bbcb31a0e>:0
"<unnamed thread>"
08-06 16:26:35.755 I/libc (11487): Requested dump for tid 11487 (ler.challengeme)
Possible related issues: https://github.com/xamarin/xamarin-android/issues/2920 https://github.com/xamarin/xamarin-android/issues/3222 https://github.com/mono/mono/issues/14772
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 11
- Comments: 24 (6 by maintainers)
For the love of god please fix this I can’t debug properly at all.
Release status update
A new Preview version has now been published that includes an initial improvement for this behavior. The improvement is intended to restore the debugging performance to be comparable to Visual Studio 2019 version 16.1, with a limitation that All Common Language Runtime Exceptions not in this list must be left unchecked under Debug > Windows > Exception Settings:
(An additional fix is planned to remove this limitation in the future.)
The improvement is included on Windows in Visual Studio 2019 version 16.4 Preview 2. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.
The improvement is not yet included in a Release version. I will update this item again when a Release version is available that includes the improvement.
Hey just wanted to say I’ve had this exact same issue! Mine happens when debugging and calling cancel() on a cancelationtokensource - but I’ve also seen it happen randomly in other scenarios.
Any news on this issue?
Thanks for the report! The team now has a test case for this issue and is investigating it. I will keep this issue updated with any potential workarounds as well as the release status of any candidate fixes.
I have been struggling with these ‘debug-time-only’ crashes for a couple weeks and only just now stumbled across this issue thread.
We were updating our app from Android 5 to Android 9 compatibility, which also meant Visual Studio 2017 to VS2019. So a lot of changes and I just though the newer tooling was bringing existing problems being swallowed up, to light. In a way I guess it did - just not in a way that was intentional.
Since the problem is caused by rapid exception throwing overwhelming Visual Studio… it forced me to audit code by the rest of the teams and resolve their bad practices. How many places people don’t do null checks and just wrap their code in
try/catchfor example. Or really tight repeating loops that start stomping on each other. (10 second loop on a web services call that takes 15 seconds with a 30 second timeout)So while the way this helped find bad code wasn’t intentional I will say it forced the finding and fixing of code that I otherwise wouldn’t have gotten the man-hour approval for if it hadn’t been so bad it was crashing Visual Studio. When you can say that to the bosses it makes them stand up and take notice
While I applaud the dev team for finding and (hopefully) fixing the issue within Visual Studio - the rest of y’all might also be able to use this as a way to get approval to fix things. We all have those situations of “do it fast for now, we’ll make it better later” that never ever get time later. So use this as leverage for time approval.
😉
Also happens on Xamarin.Android.SDK 9.4.0.51
I had this issue with android debugger, The “Restore Defaults” workaround fixed the issue
How is it going? It’s been a long time since an update has been posted.
@drjaydenm, apologies for the slow reply. I checked with the team about Visual Studio for Mac, and they let me know that the current known issue does not affect Visual Studio for Mac. The change in exception checking behavior between Visual Studio 2019 versions 16.1 and 16.2 that caused a performance problem on Windows was only applied on Windows. (I also quickly checked the user test case that demonstrated the issue on Windows and verified that I was not able to reproduce the performance problem on Visual Studio for Mac.)
If you are seeing a similar behavior on Visual Studio for Mac, then the team would be interested to take a closer look at your scenario. When you get a chance, if you could open a new issue here or via Help > Report a Problem in the IDE and include a brief re-summarization of what you’re seeing plus any example code you can share, that would be perfect. Thanks in advance!
Apologies for the lack of status updates on this item. I checked with the team and can add some new info.
Plans for fixes:
The current planned fixes carry some risk, so they are tentatively scheduled for inclusion in an upcoming Visual Studio 2019 Preview version. The behavior will be the same in the upcoming Visual Studio 2019 version 16.4 Preview 1, but a future preview after that will include candidate fixes. I will keep this item updated with the version numbers of future Preview and Release versions that include fixes.
Cause:
The team has identified that this problem happens when several exceptions are thrown (and caught) in a short time. Currently the Mono debugger is sending all of the exceptions to Visual Studio, and Visual Studio is then checking each one to determine whether Visual Studio is configured to break on the exception. The overhead of checking the exceptions is somewhat costly. When part of an app produces several exceptions in a short time, the app gets stuck waiting for Visual Studio to finish checking the exceptions.
Unfortunately, changing the exception settings in Visual Studio doesn’t currently affect the overhead, so those settings won’t help work around the issue at the moment.
Hi there, is there any timeline or plans to get this issue resolved? It happens to us when debugging 2/3 times. If I can provide any information to help out, please let me know
I started facing the same issue yesterday. In my case it also happen in randomly scenarios.
I’m using: VS 2019 16.2.1 Xamarin 16.2.0.91 Xamarin.Android.SDK 9.4.1.0 Mono Debugging for Visual Studio 16.2.6