Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpClient in AndroidApp crash again #6460

Closed
ssccinng opened this issue Apr 25, 2022 · 23 comments
Closed

HttpClient in AndroidApp crash again #6460

ssccinng opened this issue Apr 25, 2022 · 23 comments
Assignees
Labels
p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint platform/android 🤖 s/needs-attention Issue has more information and needs another look s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@ssccinng
Copy link

Description

Crash occurs when httpclient is used to access the API,No crash in previous versions。

Steps to Reproduce

use
dotnet publish -f net6.0-android -c Release
build apk, Then run the app on your phone
If httpclient is used, it will crash and try catch will not catch errors

Version with bug

Release Candidate 1 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android11

Did you find any workaround?

I found a strange step to solve this problem.
1, pack apk.
2, remove <uses-permission android:name="android.permission.INTERNET" /> in AndroidManifest.xml (Maybe any other setting)
3, pack apk again
4. add <uses-permission android:name="android.permission.INTERNET" /> in AndroidManifest.xml
5. pack apk again
6. if the packaged apk becomes smaller, the bug may be fixed

Relevant log output

No response

@ssccinng ssccinng added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Apr 25, 2022
@VincentBu VincentBu added the s/triaged Issue has been reviewed label Apr 25, 2022
@VincentBu
Copy link

not repro on 17.3.0 preview 1.0 [32420.421.main]. @ssccinng, would you like to verify the attached project?
MauiApp6460.zip

@VincentBu VincentBu added s/verified Verified / Reproducible Issue ready for Engineering Triage and removed s/triaged Issue has been reviewed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels Apr 25, 2022
@RedChops
Copy link

I was just about to post a bug for this myself. I can't get any iteration of HttpClient working (managed or native). Native crashes the app immediately on launch, Managed acts incredibly strangely. It appears to crash from a NullReferenceException, but sometimes it crashes silently, causing all code that would otherwise use the result of SendAsync to be skipped.

For example:

  1. var result = await client.SendAsync(...);
  2. var content = await result.Content.ReadAsStringAsync()
  3. [something else]

If I set a breakpoint on line 2, that breakpoint will get skipped and code will continue to execute on line 3, causing both result and content to be null.

I spent a large part of the day uninstalling all VS versions, clearing out the dotnet folder of all SDKs, reinstalling everything, etc, so everything should be clean and at the latest version.

I've attached here a small reproduction project.

NetworkTest.zip

@VincentBu I tried your example and it appears to work through the debugger, even though the UI state doesn't update.

@RedChops
Copy link

Though, I can't find this VS 17.3.0 preview 1.0 that's mentioned in many comments on tickets here, so who knows if it's fixed there.

@drasticactions
Copy link
Contributor

drasticactions commented Apr 25, 2022

VS 17.3 P1 isn't out yet, but it doesn't really matter in this case. It's going to be an SDK issue, not an IDE one.
AndroidNetworkTest.zip

Trying this on my Mac with Android SDK 32.0.300-rc.2.18
and MAUI 6.0.300-rc.2.5470, @RedChops's app crashed when I clicked on it. Wanting to try it on Android without MAUI I wrote this, AndroidNetworkTest.zip

Surprisingly, it worked. Same code. I'm not sure how MAUI is influencing this, but something weird is going on. @jonathanpeppers any ideas?

@VincentBu
Copy link

@drasticactions, you are right. Additionally, RedChops's code works on windows but fails on Android.

@MagicAndre1981
Copy link
Contributor

not repro on 17.3.0 preview 1.0 [32420.421.main].

you use a version that includes the fix, so you can't repro it.

@jonathanpeppers
Copy link
Member

I think this is the same as:
dotnet/runtime#67402

Fixed by:
dotnet/runtime#67746

Which will be in MAUI RC 2. Does the crash go away if you diable AOT for your Release build <RunAOTCompilation>false</RunAotCompilation>?

@jonathanpeppers jonathanpeppers self-assigned this Apr 25, 2022
@jonathanpeppers jonathanpeppers added this to the 6.0.300-rc.3 milestone Apr 25, 2022
@RedChops
Copy link

RedChops commented Apr 25, 2022

@jonathanpeppers The crash happens for me on both Debug and Release, no linking configured. I tried adding an explicit disable for AOT but that didn't seem to influence anything.

EDIT1: Actually, I must have had a typo in RunAOTCompilation configuration - explicitly disabling it allowed the first half of the request to complete. In about 2 minutes I'll be able to test the second half.

@RedChops
Copy link

@jonathanpeppers Well, I had an initial bit of hope. In the app that I'm developing, explicitly disabling AOT did let one request go through, but not another one. In the project I had uploaded a couple comments up, disabling AOT doesn't do anything for the sample request that it makes.

This is all using System.Net.Http.HttpClientHandler, Managed, as the HttpClient. I'm not sure if it's at all related, but if I set the HttpClient to use Xamarin.Android.Net.AndroidClientHandler, Android, instead the app crashes on launch instantly with a SIGSEGV SEGV_ACCERR.

@ssccinng
Copy link
Author

I think this is the same as: dotnet/runtime#67402

Fixed by: dotnet/runtime#67746

Which will be in MAUI RC 2. Does the crash go away if you diable AOT for your Release build <RunAOTCompilation>false</RunAotCompilation>?

It seems that this works. The app size is the same as that after my special steps above

@ssccinng
Copy link
Author

ssccinng commented Apr 25, 2022

I think this is the same as: dotnet/runtime#67402
Fixed by: dotnet/runtime#67746
Which will be in MAUI RC 2. Does the crash go away if you diable AOT for your Release build <RunAOTCompilation>false</RunAotCompilation>?

It seems that this works. The app size is the same as that after my special steps above

<RunAOTCompilation>false</RunAOTCompilation>

@jonathanpeppers
Copy link
Member

@RedChops can you get adb logcat output if something is still going wrong?

https://docs.microsoft.com/en-us/xamarin/android/deploy-test/debugging/android-debug-log

Enable additional logging before causing the crash, such as:

adb shell setprop debug.mono.log default,timing,assembly,mono_log_level=debug,mono_log_mask=all

Cause the crash, then save to a file:

adb logcat -d > adb.txt

Sharing adb.txt, should help look into this further. Thanks!

@jonathanpeppers jonathanpeppers added the s/needs-info Issue needs more info from the author label Apr 25, 2022
@ghost
Copy link

ghost commented Apr 25, 2022

Hi @ssccinng. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@RedChops
Copy link

RedChops commented Apr 25, 2022

@jonathanpeppers I have two logs here, both generated from my NetworkTest project uploaded above.

The first is AndroidClientHandler.adb.txt which is the output from using the Android HttpClient.

The second is HttpClientHandler.adb.txt. This of course includes the output from the AndroidClientHandler log since it's the same emulator boot.

Both of these logs were generated off that sample project which I created fresh specifically for this bug, so there shouldn't be anything else weird going on there. They also both were run in Debug mode with <RunAOTCompilation>False</RunAOTCompilation> set in the csproj.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Apr 25, 2022
@jonathanpeppers
Copy link
Member

@RedChops so if you're seeing this in a Debug build, then RunAOTCompilation=false won't help, because it is only enabled during Release builds by default.

I filed a new issue to track this here: dotnet/android#6961

@ssccinng seems to be the problem we solved. So closing for now, thanks! MAUI RC 2 should hopefully work for you, and I'd use the workaround for now.

@PieEatingNinjas
Copy link
Contributor

PieEatingNinjas commented May 10, 2022

I think this is the same as: dotnet/runtime#67402

Fixed by: dotnet/runtime#67746

Which will be in MAUI RC 2. Does the crash go away if you diable AOT for your Release build <RunAOTCompilation>false</RunAotCompilation>?

To me it seems like it's not fixed in RC 2...

Using RC 2, I'm getting the APK working, only when adding the above ( <RunAOTCompilation>False</RunAOTCompilation> ). Without it, the app crashes as soon as I'm making an API/web call.

Repro

When I publish this app (dotnet publish -f:net6.0-android --configuration Release --output "c:/temp"), and install the resulting APK on Android, I get the following behavior:

  • Crash when clicking the button
  • No Crash when clicking the button when <RunAOTCompilation>False</RunAOTCompilation> was added to csproj.

I'm on RC 2:
image

This is the Error-log that I extracted:

2022-05-10 14:22:02.753 25029-25870/? A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xa8 in tid 25870 (.NET ThreadPool), pid 25029 (yname.mauiapp53)
2022-05-10 14:22:02.857 25878-25878/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2022-05-10 14:22:02.857 25878-25878/? A/DEBUG: Build fingerprint: 'samsung/gtactivexleea/gtactivexl:11/RP1A.200720.012/T545XXS3CUL2_B2BF:user/release-keys'
2022-05-10 14:22:02.857 25878-25878/? A/DEBUG: Revision: '3'
2022-05-10 14:22:02.857 25878-25878/? A/DEBUG: ABI: 'arm64'
2022-05-10 14:22:02.858 25878-25878/? A/DEBUG: Timestamp: 2022-05-10 14:22:02+0200
2022-05-10 14:22:02.858 25878-25878/? A/DEBUG: pid: 25029, tid: 25870, name: .NET ThreadPool >>> com.companyname.mauiapp53 <<<
2022-05-10 14:22:02.858 25878-25878/? A/DEBUG: uid: 10320
2022-05-10 14:22:02.858 25878-25878/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xa8
2022-05-10 14:22:02.858 25878-25878/? A/DEBUG: Cause: null pointer dereference
2022-05-10 14:22:02.858 25878-25878/? A/DEBUG: x0 0000000000000012 x1 0000007bc7a4c9d1 x2 0000000000000057 x3 0000000000000045
2022-05-10 14:22:02.858 25878-25878/? A/DEBUG: x4 0000000000000000 x5 0b1d0e1715000000 x6 00000015170e1d0b x7 00000000008fb353
2022-05-10 14:22:02.858 25878-25878/? A/DEBUG: x8 0000000000000015 x9 0000000000000000 x10 0101010101010101 x11 000000000000001b
2022-05-10 14:22:02.858 25878-25878/? A/DEBUG: x12 0000000000000002 x13 0000000000000370 x14 0000000000000020 x15 1000000000000000
2022-05-10 14:22:02.858 25878-25878/? A/DEBUG: x16 0000007bc7adab30 x17 0000007cb8e49380 x18 0000007bb89bc000 x19 0000007bbcfc8c00
2022-05-10 14:22:02.858 25878-25878/? A/DEBUG: x20 0000007bc1c819f0 x21 0000007bc0243c00 x22 0000000000000000 x23 0000007bbcc27ce0
2022-05-10 14:22:02.859 25878-25878/? A/DEBUG: x24 0000007bc7ae1000 x25 0000007bc7ae1000 x26 0000007bbcd71410 x27 0000007bc7af1000
2022-05-10 14:22:02.859 25878-25878/? A/DEBUG: x28 0000007c237ad000 x29 0000007c237aa7f0
2022-05-10 14:22:02.859 25878-25878/? A/DEBUG: lr 0000007bc7838f4c sp 0000007c237aa760 pc 0000007bc7838f60 pst 0000000000000000
2022-05-10 14:22:02.864 652-652/? E/audit: type=1400 audit(1652185322.852:840548): avc: denied { read } for pid=1219 comm=43464D532048616E646C6572205468 name="gpuclk" dev="sysfs" ino=45734 scontext=u:r:system_server:s0 tcontext=u:object_r:vendor_sysfs_kgsl_gpuclk:s0 tclass=file permissive=0 SEPF_SM-T545_11_0010 audit_filtered
2022-05-10 14:22:02.990 25878-25878/? A/DEBUG: backtrace:
2022-05-10 14:22:02.990 25878-25878/? A/DEBUG: #00 pc 0000000000063f60 /data/app/~~zbHiDCoAKKNZ7yRiAc3N4A==/com.companyname.mauiapp53-lgOxwUrcIE00ngpGe18yHg==/lib/arm64/libmonosgen-2.0.so (BuildId: 370ce1ebfa2750b5b83672c75f89f294edfe4d14)
2022-05-10 14:22:02.990 25878-25878/? A/DEBUG: #1 pc 000000000000b24c anonymous:7c230a1000
2022-05-10 14:22:03.069 652-652/? E/audit: type=1400 audit(1652185323.052:840549): avc: denied { read } for pid=1219 comm=43464D532048616E646C6572205468 name="gpuclk" dev="sysfs" ino=45734 scontext=u:r:system_server:s0 tcontext=u:object_r:vendor_sysfs_kgsl_gpuclk:s0 tclass=file permissive=0 SEPF_SM-T545_11_0010 audit_filtered
2022-05-10 14:22:03.270 652-652/? E/audit: type=1400 audit(1652185323.252:840550): avc: denied { read } for pid=1219 comm=43464D532048616E646C6572205468 name="gpuclk" dev="sysfs" ino=45734 scontext=u:r:system_server:s0 tcontext=u:object_r:vendor_sysfs_kgsl_gpuclk:s0 tclass=file permissive=0 SEPF_SM-T545_11_0010 audit_filtered
2022-05-10 14:22:03.472 652-652/? E/audit: type=1400 audit(1652185323.462:840551): avc: denied { read } for pid=1219 comm=43464D532048616E646C6572205468 name="gpuclk" dev="sysfs" ino=45734 scontext=u:r:system_server:s0 tcontext=u:object_r:vendor_sysfs_kgsl_gpuclk:s0 tclass=file permissive=0 SEPF_SM-T545_11_0010 audit_filtered
2022-05-10 14:22:03.520 655-655/? E/tombstoned: Tombstone written to: /data/tombstones/tombstone_23
2022-05-10 14:22:03.574 785-825/? E/HYPER-HAL: [HandlerSysfs.cpp]doResourceHandling(): Couldn't Open Sysfs - /sys/kernel/mm/vmscan/am_app_launch
2022-05-10 14:22:03.584 1954-2839/? E/TaskStackListenerAbstract: onTaskSnapshotChanged called by Binder.getCallingPid() 0 android.app.ITaskStackListener$Stub.onTransact:587 android.os.Binder.execTransactInternal:1195 android.os.Binder.execTransact:1159
2022-05-10 14:22:03.602 2417-2417/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2022-05-10 14:22:03.639 2417-2417/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2022-05-10 14:22:03.673 652-652/? E/audit: type=1400 audit(1652185323.662:840552): avc: denied { read } for pid=1219 comm=43464D532048616E646C6572205468 name="gpuclk" dev="sysfs" ino=45734 scontext=u:r:system_server:s0 tcontext=u:object_r:vendor_sysfs_kgsl_gpuclk:s0 tclass=file permissive=0 SEPF_SM-T545_11_0010 audit_filtered
2022-05-10 14:22:03.703 2417-2417/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2022-05-10 14:22:03.765 2417-2417/? E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2022-05-10 14:22:03.782 25894-25894/? E/android.dqagen: Not starting debugger since process cannot load the jdwp agent.

@jonathanpeppers
Copy link
Member

@PieEatingNinjas can you try MAUI RC 3 that just shipped? dotnet/runtime 6.0.5 did not ship until today as well.

@PieEatingNinjas
Copy link
Contributor

@PieEatingNinjas can you try MAUI RC 3 that just shipped? dotnet/runtime 6.0.5 did not ship until today as well.

I’ll give it a try tomorrow and will let you know the results.

@PieEatingNinjas
Copy link
Contributor

Sorry for the delay.
But I can confirm that it seems to be working just fine in RC 3. No need to add <RunAOTCompilation>False</RunAOTCompilation>

@sharpninja
Copy link

Just to be clear, using SDK 6.0.300 fixes this?

@jonathanpeppers
Copy link
Member

If you have C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.android-*\6.0.5, then you have the fix.

@sharpninja
Copy link

OK, I have verified I am on the correct version, but I am still seeing this error in Uno Platform. Here is the discussion

@jonathanpeppers
Copy link
Member

I mean your error is different? NullReferenceException? I would try to make a repro in a dotnet new android project and file an issue here:

https://github.com/xamarin/xamarin-android/issues

Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Jun 18, 2022
@samhouts samhouts added the p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint label Jul 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint platform/android 🤖 s/needs-attention Issue has more information and needs another look s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants