dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.42k stars 4.76k forks source link

Mono: AOT compiler can't compile System.Net.SafeDeleteSslContext:ReadFromConnection (Mac Catalyst) #55736

Closed rolfbjarne closed 3 years ago

rolfbjarne commented 3 years ago

Description

Calling the method System.Net.SafeDeleteSslContext:ReadFromConnection in AOT compiled code leads to:

ExecutionEngineException: Attempting to JIT compile method '(wrapper native-to-managed) in System.Net.SafeDeleteSslContext:ReadFromConnection (void,byte,void**)' while running in aot-only mode.

This is the complete stack trace from our test:

[FAIL] TestNSUrlSessionHandlerCookies :   Exception
  Expected: null
  But was:  <System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
 ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
 ---> System.ExecutionEngineException: Attempting to JIT compile method '(wrapper native-to-managed) in System.Net.SafeDeleteSslContext:ReadFromConnection (void*,byte*,void**)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.
   at System.Net.SafeDeleteSslContext..ctor(SafeFreeSslCredentials credential, SslAuthenticationOptions sslAuthenticationOptions) in System.Net.Security.dll:token 0x6000191+0xfc
   at System.Net.Security.SslStreamPal.HandshakeInternal(SafeFreeCredentials credential, SafeDeleteSslContext& context, ReadOnlySpan`1 inputBuffer, Byte[]& outputBuffer, SslAuthenticationOptions sslAuthenticationOptions) in System.Net.Security.dll:token 0x6000407+0x10
 --- End of inner exception stack trace ---
   at System.Net.Security.SslStream.<ForceAuthenticationAsync>d__172`1[[System.Net.Security.AsyncReadWriteAdapter, System.Net.Security, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext() in System.Net.Security.dll:token 0x600030e+0x1f6
   at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x600051e+0x95
 --- End of inner exception stack trace ---
   at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x600051e+0x138
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x60006ff+0x410
   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x6000701+0x8f
   at System.Net.Http.HttpConnectionPool.SendUsingHttp11Async(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x60006f1+0x15d
   at System.Net.Http.HttpConnectionPool.DetermineVersionAndSendAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x60006f2+0x224
   at System.Net.Http.HttpConnectionPool.SendAndProcessAltSvcAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x60006f3+0x8e
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x60006f4+0x99
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) in System.Net.Http.dll:token 0x600022f+0x1b7
   at MonoTests.System.Net.Http.MessageHandlerTest.<>c__DisplayClass4_0.<<TestNSUrlSessionHandlerCookies>b__0>d.MoveNext() in xamarin-macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 106>
   at MonoTests.System.Net.Http.MessageHandlerTest.TestNSUrlSessionHandlerCookies() in xamarin-macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 123

This is the test code: https://github.com/xamarin/xamarin-macios/blob/f5896c14141de86a377044bb0a66bbf8f982a1bb/tests/monotouch-test/System.Net.Http/MessageHandlers.cs#L106

Binlog for the test app: build-MacCatalyst-20210715_143948.binlog.zip

This is the part of the log that corresponds to the AOT compilation: https://gist.github.com/rolfbjarne/fc9f1316a92945fdde0f38ff1ede334f

ghost commented 3 years ago

Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.

Issue Details
### Description Calling the method `System.Net.SafeDeleteSslContext:ReadFromConnection` in AOT compiled code leads to: > ExecutionEngineException: Attempting to JIT compile method '(wrapper native-to-managed) in System.Net.SafeDeleteSslContext:ReadFromConnection (void*,byte*,void**)' while running in aot-only mode. This is the complete stack trace from our test: ``` [FAIL] TestNSUrlSessionHandlerCookies : Exception Expected: null But was: System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception. ---> System.ExecutionEngineException: Attempting to JIT compile method '(wrapper native-to-managed) in System.Net.SafeDeleteSslContext:ReadFromConnection (void*,byte*,void**)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information. at System.Net.SafeDeleteSslContext..ctor(SafeFreeSslCredentials credential, SslAuthenticationOptions sslAuthenticationOptions) in System.Net.Security.dll:token 0x6000191+0xfc at System.Net.Security.SslStreamPal.HandshakeInternal(SafeFreeCredentials credential, SafeDeleteSslContext& context, ReadOnlySpan`1 inputBuffer, Byte[]& outputBuffer, SslAuthenticationOptions sslAuthenticationOptions) in System.Net.Security.dll:token 0x6000407+0x10 --- End of inner exception stack trace --- at System.Net.Security.SslStream.d__172`1[[System.Net.Security.AsyncReadWriteAdapter, System.Net.Security, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext() in System.Net.Security.dll:token 0x600030e+0x1f6 at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x600051e+0x95 --- End of inner exception stack trace --- at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x600051e+0x138 at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x60006ff+0x410 at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x6000701+0x8f at System.Net.Http.HttpConnectionPool.SendUsingHttp11Async(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x60006f1+0x15d at System.Net.Http.HttpConnectionPool.DetermineVersionAndSendAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x60006f2+0x224 at System.Net.Http.HttpConnectionPool.SendAndProcessAltSvcAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x60006f3+0x8e at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x60006f4+0x99 at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) in System.Net.Http.dll:token 0x600022f+0x1b7 at MonoTests.System.Net.Http.MessageHandlerTest.<>c__DisplayClass4_0.<b__0>d.MoveNext() in xamarin-macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 106> at MonoTests.System.Net.Http.MessageHandlerTest.TestNSUrlSessionHandlerCookies() in xamarin-macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 123 ``` This is the test code: https://github.com/xamarin/xamarin-macios/blob/f5896c14141de86a377044bb0a66bbf8f982a1bb/tests/monotouch-test/System.Net.Http/MessageHandlers.cs#L106 Binlog for the test app: [build-MacCatalyst-20210715_143948.binlog.zip](https://github.com/dotnet/runtime/files/6823188/build-MacCatalyst-20210715_143948.binlog.zip) This is the part of the log that corresponds to the AOT compilation: https://gist.github.com/rolfbjarne/fc9f1316a92945fdde0f38ff1ede334f
Author: rolfbjarne
Assignees: -
Labels: `area-System.Net`, `untriaged`
Milestone: -
rolfbjarne commented 3 years ago

CC @steveisok

steveisok commented 3 years ago

/cc @vargaz @lambdageek

steveisok commented 3 years ago

Does not seem like ReadFromConnection is doing anything strange from the libraries side.

lambdageek commented 3 years ago

We're missing pinvoke callback attributes on ReadFromConnection and WriteFromConnection. They're stored in _readCallback and _writeCallback here and then passed to SslSetIoCallbacks So they're reverse pinvokes and need the MonoPInvokeCallbackAttribute (or the .net6 thing... whose name escapes me)

ghost commented 3 years ago

Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.

Issue Details
### Description Calling the method `System.Net.SafeDeleteSslContext:ReadFromConnection` in AOT compiled code leads to: > ExecutionEngineException: Attempting to JIT compile method '(wrapper native-to-managed) in System.Net.SafeDeleteSslContext:ReadFromConnection (void*,byte*,void**)' while running in aot-only mode. This is the complete stack trace from our test: ``` [FAIL] TestNSUrlSessionHandlerCookies : Exception Expected: null But was: System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception. ---> System.ExecutionEngineException: Attempting to JIT compile method '(wrapper native-to-managed) in System.Net.SafeDeleteSslContext:ReadFromConnection (void*,byte*,void**)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information. at System.Net.SafeDeleteSslContext..ctor(SafeFreeSslCredentials credential, SslAuthenticationOptions sslAuthenticationOptions) in System.Net.Security.dll:token 0x6000191+0xfc at System.Net.Security.SslStreamPal.HandshakeInternal(SafeFreeCredentials credential, SafeDeleteSslContext& context, ReadOnlySpan`1 inputBuffer, Byte[]& outputBuffer, SslAuthenticationOptions sslAuthenticationOptions) in System.Net.Security.dll:token 0x6000407+0x10 --- End of inner exception stack trace --- at System.Net.Security.SslStream.d__172`1[[System.Net.Security.AsyncReadWriteAdapter, System.Net.Security, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext() in System.Net.Security.dll:token 0x600030e+0x1f6 at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x600051e+0x95 --- End of inner exception stack trace --- at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x600051e+0x138 at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x60006ff+0x410 at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x6000701+0x8f at System.Net.Http.HttpConnectionPool.SendUsingHttp11Async(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x60006f1+0x15d at System.Net.Http.HttpConnectionPool.DetermineVersionAndSendAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x60006f2+0x224 at System.Net.Http.HttpConnectionPool.SendAndProcessAltSvcAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x60006f3+0x8e at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) in System.Net.Http.dll:token 0x60006f4+0x99 at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) in System.Net.Http.dll:token 0x600022f+0x1b7 at MonoTests.System.Net.Http.MessageHandlerTest.<>c__DisplayClass4_0.<b__0>d.MoveNext() in xamarin-macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 106> at MonoTests.System.Net.Http.MessageHandlerTest.TestNSUrlSessionHandlerCookies() in xamarin-macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 123 ``` This is the test code: https://github.com/xamarin/xamarin-macios/blob/f5896c14141de86a377044bb0a66bbf8f982a1bb/tests/monotouch-test/System.Net.Http/MessageHandlers.cs#L106 Binlog for the test app: [build-MacCatalyst-20210715_143948.binlog.zip](https://github.com/dotnet/runtime/files/6823188/build-MacCatalyst-20210715_143948.binlog.zip) This is the part of the log that corresponds to the AOT compilation: https://gist.github.com/rolfbjarne/fc9f1316a92945fdde0f38ff1ede334f
Author: rolfbjarne
Assignees: -
Labels: `area-System.Net`, `untriaged`
Milestone: -