android: Application random freezes

Android application type

Classic Xamarin.Android (MonoAndroid12.0, etc.)

Affected platform version

Visual Studio 2019 (16.4.4) with Xamarin (16.4.000.309)

Description

We have an application running on Android 7.1.1, developed with Xamarin.

This application is running 24h/24 on a device with screen always on. This application manages a lot of data, so it causes a lot of garbage collection events (one every 10 seconds, approximately).

Issue: sometimes, after some days, the application freezes without any error in the logs (logcat/dmesg). In this state, the app does not respond to touches or adb commands and no logs is printed anymore by the application.

Debugging, we saw that when the app freezes, the app process is in the sigsuspend status (ps command): system 15111 220 1877900 263016 sigsuspend b011d640 S com.android.app

We then took a strace of the process (attached) where we can see that the app enters the sigsuspend status here: --- SIGPWR {si_signo=SIGPWR, si_code=SI_TKILL, si_pid=1562, si_uid=1000} --- rt_sigprocmask(SIG_BLOCK, [XCPU], [HUP INT QUIT ILL TRAP ABRT BUS FPE USR1 SEGV USR2 PIPE ALRM TERM STKFLT CHLD CONT TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH IO PWR SYS RTMIN], 8) = 0 futex(0xa5d0c5c4, FUTEX_WAKE_PRIVATE, 2147483647) = 1 rt_sigsuspend([HUP INT QUIT ILL TRAP ABRT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XFSZ VTALRM PROF WINCH IO PWR SYS RTMIN], 8

strace_full.txt

Basically, when the issue appears the rt_sigsuspend function never returns. It is my understanding that the SIGPWR and SIGXCPU signals are used by Mono to manage the garbage collections. We tried with the tarjar implementation and with the old GC implementation: we have the issue with both, but using the old implementation the GC events are rarer (one every 70 seconds).

Steps to Reproduce

It’s very difficult to replicate the issue, as it requires a specific application running on a specific hardware.

Did you find any workaround?

The only way to get the application running again is to close it and reopen it, but this is not something feasible with our use case.

Relevant log output

At every GC event:
01-17 04:00:59.386  1385  1427 I art     : Starting a blocking GC Explicit
01-17 04:00:59.401  1385  1419 I Mono    : GC_BRIDGE waiting for bridge processing to finish
01-17 04:00:59.438  1385  1427 I art     : Explicit concurrent mark sweep GC freed 13111(711KB) AllocSpace objects, 0(0B) LOS objects, 40% free, 3MB/5MB, paused 885us total 51.839ms
01-17 04:00:59.438  1385  1394 I Mono    : GC_BRIDGE waiting for bridge processing to finish
01-17 04:00:59.446  1385  1427 I Mono    : GC_TAR_BRIDGE bridges 457 objects 457 opaque 122 colors 457 colors-bridged 457 colors-visible 457 xref 61 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.22ms tarjan 0.51ms scc-setup 0.29ms gather-xref 0.04ms xref-setup 0.03ms cleanup 0.21ms
01-17 04:00:59.446  1385  1427 I Mono    : GC_BRIDGE: Complete, was running for 62.56ms
01-17 04:00:59.446  1385  1427 I Mono    : GC_MINOR: (Nursery full) time 13.00ms, stw 14.43ms promoted 85K major size: 6448K in use: 5109K los size: 4096K in use: 239K

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (10 by maintainers)

Most upvoted comments

I just wanted to report that we have concluded that this is a proper workaround for the application freeze issue we were seeing. Thanks again to everyone for your help!

is it possible to migrate our apps to NET6 at this point without MAUI

@jfichtner The official guidance is that MAUI is supported way to build mobile applications using .NET 6.

However MAUI is built atop the .NET for Android SDK, so if you make an SDK-style project using the net6.0-android runtime identifier and reference the appropriate nugets, you will get an Android APK. See, for example https://github.com/dotnet/maui-samples/tree/main/archive/HelloAndroid

Note that moving from pre-.NET6 Xamarin.Android to the .NET 6 Android SDK has all the same issues as moving from .NET Framework 4.x to .NET Core 3.x (or to .NET 5 or 6) on desktop - if you use AppDomains, or other legacy APIs they may not be available.