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

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

Closed
rolfbjarne opened this issue Jul 15, 2021 · 6 comments · Fixed by #55947
Assignees
Labels
Milestone

Comments

@rolfbjarne
Copy link
Member

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

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Net untriaged New issue has not been triaged by the area owner labels Jul 15, 2021
@ghost
Copy link

ghost commented Jul 15, 2021

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.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

Author: rolfbjarne
Assignees: -
Labels:

area-System.Net, untriaged

Milestone: -

@rolfbjarne
Copy link
Member Author

CC @steveisok

@steveisok
Copy link
Member

/cc @vargaz @lambdageek

@steveisok
Copy link
Member

steveisok commented Jul 15, 2021

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

@lambdageek
Copy link
Member

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
Copy link

ghost commented Jul 15, 2021

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.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

Author: rolfbjarne
Assignees: -
Labels:

area-System.Net, untriaged

Milestone: -

@steveisok steveisok added this to the 6.0.0 milestone Jul 15, 2021
@steveisok steveisok removed the untriaged New issue has not been triaged by the area owner label Jul 15, 2021
@karelz karelz added os-maccatalyst MacCatalyst OS runtime-mono specific to the Mono runtime labels Jul 15, 2021
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jul 16, 2021
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jul 16, 2021
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jul 21, 2021
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jul 22, 2021
@steveisok steveisok added the in-pr There is an active PR which will close this issue when it is merged label Aug 16, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Aug 17, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Sep 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
6 participants