runtime: HttpClient crashes android app when trimmed

Description

It appears that https://github.com/dotnet/runtime/pull/64818 caused a regression in Maui Android apps using HttpClient.

Reproduction Steps

  1. clone https://github.com/eerhardt/MauiHttpBug.git
  2. dotnet restore
  3. dotnet build -t:Run -f net6.0-android -r android-arm64 --no-restore Launch the app and click the ‘Click me’ button

The button changes the text to “Searching…” and then “Length: 93025”.

  1. dotnet build -t:Run -c Release -f net6.0-android -r android-arm64 --no-restore Launch the app and click the ‘Click me’ button

The app crashes

Expected behavior

The app should work the same in Debug and Release.

Actual behavior

The app works in Debug. But crashes in Release.

Regression?

Yes. This worked in Maui Preview 14. But it is broken in Maui main.

Known Workarounds

No response

Configuration

No response

Other information

logcat output with adb shell setprop debug.mono.log default,timing=bare,assembly,mono_log_level=debug,mono_log_mask=all:

03-31 16:35:21.984 29216 29251 D Mono    : AOT: FOUND method System.Net.Http.HttpResponseMessage:EnsureSuccessStatusCode () [0x77cdea0840 - 0x77cdea0960 0x77cdeba546]
03-31 16:35:21.984 29216 29251 D Mono    : AOT: FOUND method System.Net.Http.HttpResponseMessage:get_IsSuccessStatusCode () [0x77cdea06c0 - 0x77cdea0710 0x77cdeba537]
03-31 16:35:21.984 29216 29251 D Mono    : AOT: FOUND method System.Net.Http.HttpContent:TryReadAsStream () [0x77cde9d820 - 0x77cde9da00 0x77cdeba3f6]
03-31 16:35:21.984 29216 29251 D Mono    : AOT: FOUND method System.Net.Http.HttpContent:CheckDisposed () [0x77cde9e0f0 - 0x77cde9e160 0x77cdeba428]
03-31 16:35:21.984 29216 29251 D Mono    : AOT: FOUND method System.Net.Http.HttpContent:TryGetBuffer (System.ArraySegment`1<byte>&) [0x77cde9d500 - 0x77cde9d580 0x77cdeba3df]
03-31 16:35:21.984 29216 29251 D Mono    : AOT: FOUND method System.Net.Http.StreamContent:TryCreateContentReadStream () [0x77cdea1690 - 0x77cdea1750 0x77cdeba5b6]
03-31 16:35:21.984 29216 29251 D Mono    : AOT: FOUND method System.Net.Http.Headers.HttpContentHeaders:get_ContentLength () [0x77cdeaaee0 - 0x77cdeab0d0 0x77cdebac29]
03-31 16:35:21.984 29216 29251 D Mono    : AOT: FOUND method System.Net.Http.Headers.KnownHeader:get_Descriptor () [0x77cdea3420 - 0x77cdea3480 0x77cdeba61d]
03-31 16:35:21.984 29216 29251 D Mono    : AOT: FOUND method System.Net.Http.Headers.HttpHeaders:GetParsedValues (System.Net.Http.Headers.HeaderDescriptor) [0x77cdeac9a0 - 0x77cdeaca10 0x77cdebacdb]
03-31 16:35:21.984 29216 29251 D Mono    : AOT: NOT FOUND: System.Net.Http.HttpContent:GetComputedOrBufferLength ().
03-31 16:35:21.984 29216 29251 D Mono    : AOT: NOT FOUND: System.Net.Http.HttpContent:GetComputedOrBufferLength ().
03-31 16:35:21.985 29216 29251 D Mono    : AOT: NOT FOUND: System.Net.Http.StreamContent:TryComputeLength (long&).
03-31 16:35:21.985 29216 29251 D Mono    : AOT: NOT FOUND: System.Net.Http.StreamContent:TryComputeLength (long&).
03-31 16:35:21.985 29216 29251 D Mono    : AOT: FOUND method System.Net.Http.HttpContent/LimitArrayPoolWriteStream:.ctor (int,long) [0x77cde9e900 - 0x77cde9ea00 0x77cdeba467]
03-31 16:35:21.985 29216 29251 D Mono    : Running class .cctor for System.Buffers.TlsOverPerCoreLockedStacksArrayPool`1/PerCoreLockedStacks<byte> from 'System.Private.CoreLib.dll'
03-31 16:35:21.985 29216 29251 D Mono    : AOT: FOUND method System.Buffers.TlsOverPerCoreLockedStacksArrayPool`1/PerCoreLockedStacks<byte>:.cctor () [0x77d03070e0 - 0x77d0307150 0x77d033a2a9]
03-31 16:35:21.985 29216 29251 D Mono    : AOT: FOUND method System.Buffers.TlsOverPerCoreLockedStacksArrayPool`1<byte>:Rent (int) [0x77d0307150 - 0x77d0307550 0x77d033a2b8]
03-31 16:35:21.985 29216 29251 D Mono    : AOT: FOUND method System.IO.Stream:CopyToAsync (System.IO.Stream,System.Threading.CancellationToken) [0x77d02d6640 - 0x77d02d66b0 0x77d0338cd8]
03-31 16:35:21.985 29216 29251 D Mono    : AOT: FOUND method System.IO.Stream:GetCopyBufferSize () [0x77d02d6770 - 0x77d02d6840 0x77d0338ce6]
03-31 16:35:21.985 29216 29251 D Mono    : AOT: FOUND method System.IO.DelegatingStream:get_CanSeek () [0x77cde9a570 - 0x77cde9a5c0 0x77cdeba2bf]
03-31 16:35:21.985 29216 29251 D Mono    : AOT: FOUND method System.IO.DelegatingStream:CopyToAsync (System.IO.Stream,int,System.Threading.CancellationToken) [0x77cde9a610 - 0x77cde9a670 0x77cdeba2c7]
03-31 16:35:21.985 29216 29251 D Mono    : AOT: FOUND method System.IO.BufferedStream:CopyToAsync (System.IO.Stream,int,System.Threading.CancellationToken) [0x77d02d8dc0 - 0x77d02d8e70 0x77d0338e12]
03-31 16:35:21.985 29216 29251 D Mono    : AOT: FOUND method System.IO.Stream:ValidateCopyToArguments (System.IO.Stream,int) [0x77d02d7780 - 0x77d02d78a0 0x77d0338d91]
03-31 16:35:21.985 29216 29251 D Mono    : AOT: FOUND method System.Net.Http.HttpContent/LimitArrayPoolWriteStream:get_CanWrite () [0x77cde9ef10 - 0x77cde9ef30 0x77cdeba48d]
03-31 16:35:21.985 29216 29251 D Mono    : AOT: FOUND method System.IO.BufferedStream:EnsureCanRead () [0x77d02d8ac0 - 0x77d02d8b20 0x77d0338e02]
03-31 16:35:21.985 29216 29251 D Mono    : AOT: FOUND method System.IO.BufferedStream:CopyToAsyncCore (System.IO.Stream,int,System.Threading.CancellationToken) [0x77d02d8e70 - 0x77d02d8fa0 0x77d0338e16]
03-31 16:35:21.985 29216 29251 D Mono    : AOT: FOUND method System.Runtime.CompilerServices.AsyncMethodBuilderCore:Start<System.IO.BufferedStream/<CopyToAsyncCore>d__69> (System.IO.BufferedStream/<CopyToAsyncCore>d__69&) [0x77d0307550 - 0x77d03076e0 0x77d033a2c9]
03-31 16:35:21.985 29216 29251 D Mono    : AOT: FOUND method System.IO.BufferedStream/<CopyToAsyncCore>d__69:MoveNext () [0x77d02d8fa0 - 0x77d02d9da0 0x77d0338e1a]
03-31 16:35:21.985 29216 29251 D Mono    : AOT: FOUND method System.IO.Stream:EnsureAsyncActiveSemaphoreInitialized () [0x77d02d6530 - 0x77d02d6640 0x77d0338cce]
03-31 16:35:21.986 29216 29251 D Mono    : AOT: FOUND method System.Threading.SemaphoreSlim:WaitAsync (System.Threading.CancellationToken) [0x77d0298e40 - 0x77d0298e90 0x77d0336a77]
03-31 16:35:21.986 29216 29251 D Mono    : AOT: FOUND method System.Threading.SemaphoreSlim:WaitAsync (int,System.Threading.CancellationToken) [0x77d0298e90 - 0x77d0299130 0x77d0336a7e]
03-31 16:35:21.986 29216 29251 D Mono    : AOT: FOUND method System.Threading.SemaphoreSlim:CheckDispose () [0x77d0299420 - 0x77d0299480 0x77d0336a99]
03-31 16:35:21.986 29216 29251 D Mono    : AOT: FOUND method System.Threading.Tasks.Task:FromResult<bool> (bool) [0x77d03076e0 - 0x77d0307da0 0x77d033a2cd]
03-31 16:35:21.986 29216 29251 D Mono    : AOT: FOUND method System.IO.Stream:CopyToAsync (System.IO.Stream,int,System.Threading.CancellationToken) [0x77d02d66b0 - 0x77d02d6770 0x77d0338cdf]
03-31 16:35:21.986 29216 29251 D Mono    : AOT: FOUND method System.IO.Stream:<CopyToAsync>g__Core|29_0 (System.IO.Stream,System.IO.Stream,int,System.Threading.CancellationToken) [0x77d02d7920 - 0x77d02d7a50 0x77d0338dae]
03-31 16:35:21.986 29216 29251 D Mono    : AOT: FOUND method System.Runtime.CompilerServices.AsyncMethodBuilderCore:Start<System.IO.Stream/<<CopyToAsync>g__Core|29_0>d> (System.IO.Stream/<<CopyToAsync>g__Core|29_0>d&) [0x77d0307da0 - 0x77d0307f30 0x77d033a33d]
03-31 16:35:21.986 29216 29251 D Mono    : AOT: FOUND method System.IO.Stream/<<CopyToAsync>g__Core|29_0>d:MoveNext () [0x77d02d7e20 - 0x77d02d8940 0x77d0338ddc]
03-31 16:35:21.986 29216 29251 D Mono    : AOT: FOUND method System.IO.Stream:ReadAsync (System.Memory`1<byte>,System.Threading.CancellationToken) [0x77d02d6c50 - 0x77d02d6e10 0x77d0338d1c]
03-31 16:35:21.986 29216 29251 D Mono    : AOT: FOUND method System.Runtime.InteropServices.MemoryMarshal:TryGetArray<byte> (System.ReadOnlyMemory`1<byte>,System.ArraySegment`1<byte>&) [0x77d0307f30 - 0x77d03081a0 0x77d033a341]
03-31 16:35:21.986 29216 29251 D Mono    : AOT: FOUND method System.IO.Stream:ReadAsync (byte[],int,int,System.Threading.CancellationToken) [0x77d02d6bd0 - 0x77d02d6c50 0x77d0338d15]
03-31 16:35:21.986 29216 29251 D Mono    : Running class .cctor for System.IO.Stream/<>c from 'System.Private.CoreLib.dll'
03-31 16:35:21.986 29216 29251 D Mono    : AOT: FOUND method System.IO.Stream/<>c:.cctor () [0x77d02d7c20 - 0x77d02d7c80 0x77d0338dbd]
03-31 16:35:21.986 29216 29251 D Mono    : AOT: FOUND method System.IO.Stream:BeginEndReadAsync (byte[],int,int) [0x77d02d6e10 - 0x77d02d7170 0x77d0338d26]
03-31 16:35:21.986 29216 29251 D Mono    : AOT NOT FOUND: (wrapper managed-to-native) System.IO.Stream:HasOverriddenBeginEndRead (System.IO.Stream).
--------- beginning of crash
03-31 16:35:21.987 29216 29251 F libc    : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xa8 in tid 29251 (.NET ThreadPool), pid 29216 (me.mauihttptest)
03-31 16:35:22.036 29260 29260 I crash_dump64: obtaining output fd from tombstoned, type: kDebuggerdTombstoneProto
03-31 16:35:22.037   740   740 I tombstoned: received crash request for pid 29251
03-31 16:35:22.038 29260 29260 I crash_dump64: performing dump of process 29216 (target tid = 29251)
03-31 16:35:22.050 29260 29260 E DEBUG   : failed to read /proc/uptime: Permission denied
03-31 16:35:22.187  1700  2186 D ConnectivityService: NetReassign [no changes]
03-31 16:35:22.285 29260 29260 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
03-31 16:35:22.285 29260 29260 F DEBUG   : Build fingerprint: 'google/barbet/barbet:12/SP2A.220305.012/8177914:user/release-keys'
03-31 16:35:22.285 29260 29260 F DEBUG   : Revision: 'MP1.0'
03-31 16:35:22.285 29260 29260 F DEBUG   : ABI: 'arm64'
03-31 16:35:22.285 29260 29260 F DEBUG   : Timestamp: 2022-03-31 16:35:22.049905644-0500
03-31 16:35:22.285 29260 29260 F DEBUG   : Process uptime: 0s
03-31 16:35:22.285 29260 29260 F DEBUG   : Cmdline: com.companyname.mauihttptest
03-31 16:35:22.285 29260 29260 F DEBUG   : pid: 29216, tid: 29251, name: .NET ThreadPool  >>> com.companyname.mauihttptest <<<
03-31 16:35:22.285 29260 29260 F DEBUG   : uid: 10003
03-31 16:35:22.285 29260 29260 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xa8
03-31 16:35:22.285 29260 29260 F DEBUG   : Cause: null pointer dereference
03-31 16:35:22.285 29260 29260 F DEBUG   :     x0  0000000000000012  x1  00000077d39339d1  x2  0000000000000057  x3  0000000000000045
03-31 16:35:22.285 29260 29260 F DEBUG   :     x4  0000000000000000  x5  0e17150000000000  x6  000000000015170e  x7  0000000001cdd485
03-31 16:35:22.285 29260 29260 F DEBUG   :     x8  0000000000000015  x9  0000000000000000  x10 0101010101010101  x11 000000000000002b
03-31 16:35:22.285 29260 29260 F DEBUG   :     x12 0000ffff00000eff  x13 000000004667a813  x14 0000000000000000  x15 b4000079dabdb0e8
03-31 16:35:22.285 29260 29260 F DEBUG   :     x16 00000077d39c1b30  x17 0000007b04022400  x18 00000077bc7fc000  x19 b40000799a5f0a80
03-31 16:35:22.285 29260 29260 F DEBUG   :     x20 b4000079dab4fdd0  x21 b40000795a6a4f00  x22 0000000000000000  x23 b4000079dac04730
03-31 16:35:22.285 29260 29260 F DEBUG   :     x24 00000077d39c8000  x25 00000077d39c8000  x26 b4000079ba5b5e90  x27 00000077d39d8000
03-31 16:35:22.285 29260 29260 F DEBUG   :     x28 00000077c25fa000  x29 00000077c25f77d0
03-31 16:35:22.285 29260 29260 F DEBUG   :     lr  00000077d371ff4c  sp  00000077c25f7740  pc  00000077d371ff60  pst 0000000000001000
03-31 16:35:22.285 29260 29260 F DEBUG   : backtrace:
03-31 16:35:22.285 29260 29260 F DEBUG   :       #00 pc 0000000000063f60  /data/app/~~ET489rxyFoPnnjh7rFJE0g==/com.companyname.mauihttptest-mtD1ftQyU-s0Qllc6-WAiQ==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (BuildId: adc75f33b34c3a43641c4665d42a3ebfa736f9a3)
03-31 16:35:22.285 29260 29260 F DEBUG   :       #01 pc 000000000000e794  <anonymous:7af51e8000>
03-31 16:35:22.299   740   740 E tombstoned: Tombstone written to: tombstone_12
03-31 16:35:22.300  1700 29263 W ActivityTaskManager:   Force finishing activity com.companyname.mauihttptest/crc6455d0126993bd38e6.MainActivity
03-31 16:35:22.301  1700 29264 I DropBoxManagerService: add tag=data_app_native_crash isTagEnabled=true flags=0x2
03-31 16:35:22.307  1700  2106 I BootReceiver: Copying /data/tombstones/tombstone_12 to DropBox (SYSTEM_TOMBSTONE)
03-31 16:35:22.307  1700  2106 I DropBoxManagerService: add tag=SYSTEM_TOMBSTONE isTagEnabled=true flags=0x6
03-31 16:35:22.316   943   943 I Zygote  : Process 29216 exited due to signal 11 (Segmentation fault)
03-31 16:35:22.320  1700  1868 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.stats.service.DropBoxEntryAddedReceiver
03-31 16:35:22.320  1700  3804 I ActivityManager: Process com.companyname.mauihttptest (pid 29216) has died: fg  TOP 
03-31 16:35:22.321  1700  1739 I WindowManager: WIN DEATH: Window{b7d5fff u0 com.companyname.mauihttptest/crc6455d0126993bd38e6.MainActivity}
03-31 16:35:22.322  1700  2106 I DropBoxManagerService: add tag=SYSTEM_TOMBSTONE_PROTO isTagEnabled=true flags=0x4
03-31 16:35:22.322  1700  1739 W InputManager-JNI: Input channel object 'b7d5fff com.companyname.mauihttptest/crc6455d0126993bd38e6.MainActivity (client)' was disposed without first being removed with the input manager!

cc @steveisok

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

@steveisok I will add tests tomorrow and I can create a PR with the fix @eerhardt found

I think I fixed it by doing:

ves_icall_System_IO_Stream_HasOverriddenBeginEndRead (MonoObjectHandle stream, MonoError *error)
{
	MonoClass* curr_klass = MONO_HANDLE_GET_CLASS (stream);
+	mono_class_setup_vtable (curr_klass);

Adding that line causes my app to no longer crash.

When AOT is disabled the app doesn’t crash when the button is clicked:

dotnet build -c Release -t:Run -f net6.0-android -r android-arm64 --no-restore -p:AotAssemblies=false

I don’t think the regression is caused by #64818 but I don’t have any other hypothesis so far.

@simonrozsival It may be that the linker is trimming too much. Please investigate.