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

Unknown socket error #64305

Open
slidecraft104 opened this issue Jan 26, 2022 · 83 comments
Open

Unknown socket error #64305

slidecraft104 opened this issue Jan 26, 2022 · 83 comments
Labels
area-System.Runtime documentation Documentation bug or enhancement, does not impact product or test code
Milestone

Comments

@slidecraft104
Copy link

slidecraft104 commented Jan 26, 2022

Description

We have an application based on template dotnet create webapi project template and just adds an IHostedService to do background processing. Kestrel is used in order to be able to answer health checks from Kubernetes, as well as feed new requests into the service to be queued. Our background processing logic involves pretty heavy interaction with AWS resources (SQS, S3, STS), and we are encountering SocketExceptions that have been very difficult to pin down.

The canon guidance to use a static HttpClient instance application-wide does not work well when using the AWS clients in Amazon's SDK packages. The various AWS client constructors, and the config objects you can hand in, do not accept an instance of HttpClient. Instead, you must either rely on their built-in caching of HttpClient instance(s) that are created internally, or you have to provide an implementation that derives from their HttpClientFactory. This is fairly straight-forward if you use IHttpClientFactory in .Net. The Create() method override that you implement simply calls .Create() on an instance of IHttpClientFactory provided via DI.

However, even when providing this HttpClientFactory to all instances of any AWS client that is instantiated anywhere and everywhere in this service, it does not solve the SocketException problem. I will provide the stack trace below, but the properties of the actual SocketException object are extremely unhelpful:

Unknown socket error; ErrorCode: -131074; SocketErrorCode: SocketError; NativeErrorCode: -131074

The twist here is that these errors have only been encountered on Linux/in containers. Extended running tests on Windows cannot reproduce the problem when tested under load.

The other twist is that our Kestrel calls are producing System.InvalidOperationException: Handle is already used by another Socket. errors (they are logged as Warning level) in Kestrel's handling pipeline. It would appear that Kestrel, and the HttpWebRequest pool used underneath IHttpClientFactory are stomping on each other. If I am mischaracterizing the issue and there is a different cause, please let me know.

The fact that the runtime is throwing a SocketException with an error code that isn't even in the spec for TCP errors (nice article here) is the reason I am bringing it to this group. The runtime is burping up what would appear to be the equivalent of the default case in a switch statement.

Any help or guidance here is appreciated.

Reproduction Steps

The basic structure is a Web API project created with dotnet create webapi with an IHostedService doing background processing interacting heavily with AWS resources. I can provide application code privately, as needed, so as to not have to share proprietary/private logic and access keys publicly.

Expected behavior

Interaction with AWS resources from a web application should not cause SocketExceptions.

Actual behavior

We are encountering SocketExceptions that have error codes that aren't even part of the TCP specs:

Unknown socket error; ErrorCode: -131074; SocketErrorCode: SocketError; NativeErrorCode: -131074

Full stack trace:

System.Net.Http.HttpRequestException: Unknown socket error (sqs.us-west-2.amazonaws.com:443)
 ---> System.Net.Sockets.SocketException (0xFFFDFFFE): Unknown socket error
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(HttpRequestMessage request)
   at System.Threading.Tasks.TaskCompletionSourceWithCancellation1.WaitWithCancellationAsync(CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Extensions.Http.PolicyHttpMessageHandler.SendCoreAsync(HttpRequestMessage request, Context context, CancellationToken cancellationToken)
   at Polly.Retry.AsyncRetryEngine.ImplementationAsync[TResult](Func3 action, Context context, CancellationToken cancellationToken, ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates1 shouldRetryResultPredicates, Func5 onRetryAsync, Int32 permittedRetryCount, IEnumerable1 sleepDurationsEnumerable, Func4 sleepDurationProvider, Boolean continueOnCapturedContext)
   at Polly.AsyncPolicy1.ExecuteAsync(Func3 action, Context context, CancellationToken cancellationToken, Boolean continueOnCapturedContext)
   at Microsoft.Extensions.Http.PolicyHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
   at Amazon.Runtime.Internal.HttpHandler1.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.SQS.Internal.ValidationResponseHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
   at <our code starts here>

Regression?

The application in its current form is a .Net 6 solution. In a prior version, it was .Net 5 and the SocketExceptions were very rare if not non-existent.

However, even in the .Net 5 solution Kestrel was throwing the System.InvalidOperationException: Handle is already used by another Socket. warnings when handling basic health check calls.

Known Workarounds

We have implemented heavy retry policies using Polly, which allows the application to move past the errors, but it quite often takes a near complete restart of the background processing logic to clear up the SocketExceptions and allow the application to restart a job and create new connections to the AWS resources being used.

Configuration

  • .NET 6.
  • Ubuntu 20.04 via the base docker images provided directly by Microsoft
  • x64, Kubernetes in AWS EKS

The errors only appear running in containers on Linux.

Other information

N/A

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Net.Http untriaged New issue has not been triaged by the area owner labels Jan 26, 2022
@ghost
Copy link

ghost commented Jan 26, 2022

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

Issue Details

Description

We are POC'ing a basic microservice architecture that uses the template dotnet create webapi project and just adds an IHostedService to do background processing. Kestrel is used in order to be able to answer health checks from Kubernetes, so this basic architectural idea seems to make sense. Our background work for this POC involves pretty heavy interaction with AWS resources (SQS, S3, STS), and we are encountering SocketExceptions that have been very difficult to pin down.

The canon guidance to use a static HttpClient instance application-wide does not work well when using the AWS clients in Amazon's SDK packages. The various AWS client constructors, and the config objects you can hand in, do not accept an instance of HttpClient. Instead, you must either rely on their built-in caching of HttpClient instance(s) that are created internally, or you have to provide an implementation that derives from their HttpClientFactory. This is fairly straight-forward if you use IHttpClientFactory in .Net. The Create() method override that you implement simply calls .Create() on an instance of IHttpClientFactory provided via DI.

However, even when providing this HttpClientFactory to all instances of any AWS client that is instantiated anywhere and everywhere in this service, it does not solve the SocketException problem. I will provide the stack trace below, but the properties of the actual SocketException object are extremely unhelpful:

Unknown socket error; ErrorCode: -131074; SocketErrorCode: SocketError; NativeErrorCode: -131074

The twist here is that these errors have only been encountered on Linux/in containers. Extended running tests on Windows cannot reproduce the problem when tested under load.

The other twist is that our health checks calls are producing System.InvalidOperationException: Handle is already used by another Socket. errors (they are logged as Warning level) in Kestrel's handling pipeline. It would appear that Kestrel, and the HttpWebRequest pool used underneath IHttpClientFactory are stomping on each other.

Given that this architectural choice of using a WebApplication to host a long-lived service doing background processing seems the most ideal and straightforward way of designing basic microservices, we would like to get to the bottom of this issue and figure out a way to have Kestrel and IHttpClientFactory play nice. If I am mischaracterizing the issue and there is a different cause, again, we'd very much like to get to the bottom of it.

The fact that the runtime is throwing a SocketException with an error code that isn't even in the spec for TCP errors (nice article here) is the reason I am bringing it to this group. The runtime is burping up what would appear to be the equivalent of the default case in a switch statement.

Any help or guidance here is appreciated.

Reproduction Steps

The basic structure is a web api project created with dotnet create webapi with an IHostedService doing background processing interacting heavily with AWS resources. I can provide application code privately, as needed, so as to not have to share proprietary/private logic and access keys publicly.

Expected behavior

Interaction with AWS resources from a web application should not cause SocketExceptions.

Actual behavior

We are encountering SocketExceptions that have error codes that aren't even part of the TCP specs:

Unknown socket error; ErrorCode: -131074; SocketErrorCode: SocketError; NativeErrorCode: -131074

Full stack trace:

System.Net.Http.HttpRequestException: Unknown socket error (sqs.us-west-2.amazonaws.com:443) ---> System.Net.Sockets.SocketException (0xFFFDFFFE): Unknown socket error at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(HttpRequestMessage request) at System.Threading.Tasks.TaskCompletionSourceWithCancellation1.WaitWithCancellationAsync(CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Extensions.Http.PolicyHttpMessageHandler.SendCoreAsync(HttpRequestMessage request, Context context, CancellationToken cancellationToken) at Polly.Retry.AsyncRetryEngine.ImplementationAsync[TResult](Func3 action, Context context, CancellationToken cancellationToken, ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates1 shouldRetryResultPredicates, Func5 onRetryAsync, Int32 permittedRetryCount, IEnumerable1 sleepDurationsEnumerable, Func4 sleepDurationProvider, Boolean continueOnCapturedContext) at Polly.AsyncPolicy1.ExecuteAsync(Func3 action, Context context, CancellationToken cancellationToken, Boolean continueOnCapturedContext) at Microsoft.Extensions.Http.PolicyHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken) at Amazon.Runtime.Internal.HttpHandler1.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext) at Amazon.SQS.Internal.ValidationResponseHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext) at <our code starts here>

Regression?

The application in its current form is a .Net 6 solution. In a prior version, it was .Net 5 and the SocketExceptions were very rare if not non-existent.

However, even in the .Net 5 solution Kestrel was throwing the System.InvalidOperationException: Handle is already used by another Socket. warnings when handling basic health check calls.

Known Workarounds

We have implemented heavy retry policies using Polly, which allows the application to move past the errors, but it quite often takes a near complete restart of the background processing logic to clear up the SocketExceptions and allow the application to restart a job and create new connections to the AWS resources being used.

Configuration

  • .NET 6.
  • Ubuntu 20.04 via the base docker images provided directly by Microsoft
  • x64, Kubernetes in AWS EKS

The errors only appear running in containers on Linux.

Other information

No response

Author: sliderhouserules
Assignees: -
Labels:

area-System.Net.Http, untriaged

Milestone: -

@wfurt wfurt added the os-linux Linux OS (any supported distro) label Jan 26, 2022
@wfurt
Copy link
Member

wfurt commented Jan 26, 2022

Any chance you can run it under strace to see what is happening at OS level? The error will likely come from kernel so base OS is probably more important than the container.
cc: @tmds

@karelz karelz added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jan 26, 2022
@ghost
Copy link

ghost commented Jan 26, 2022

This issue has been marked needs-author-action since it may be missing important information. Please refer to our contribution guidelines for tips on how to report issues effectively.

@tmds
Copy link
Member

tmds commented Jan 26, 2022

The error code we get isn't helpful.

Unknown socket error; ErrorCode: -131074; SocketErrorCode: SocketError; NativeErrorCode: -131074

From the stacktrace we see the exception occurs during connect to sqs.us-west-2.amazonaws.com:443.

If you let .NET generate a trace for the app, the Private.InternalDiagnostics.System.Net* and System.Net* event sources may tell us more about when connect fails (e.g. during name resolution, or when making the socket connect).

The other exception is different problem:

System.InvalidOperationException: Handle is already used by another Socket.

This exception can happen when multiple Socket instances perform async I/O on the same underlying file descriptor. Does your app do this? The stacktrace can tell us more.

@slidecraft104
Copy link
Author

slidecraft104 commented Jan 26, 2022

From the stacktrace we see the exception occurs during connect to sqs.us-west-2.amazonaws.com:443.

If you let .NET generate a trace for the app, the Private.InternalDiagnostics.System.Net* and System.Net* event sources may tell us more about when connect fails (e.g. during name resolution, or when making the socket connect).

Are you talking about running strace as Tomas suggested? I don't know much about this utility yet, but I have access to open a shell into the pods so I can run this. Or are you talking about dotnet-counters or something? I could run that too, I've used it before.

The other exception is different problem:

System.InvalidOperationException: Handle is already used by another Socket.

This exception can happen when multiple Socket instances perform async I/O on the same underlying file descriptor. Does your app do this? The stacktrace can tell us more.

Yeah, I brought this part up because I have strong suspicions that this may be what is causing all of the problems. This part of the issue has existed since the inception of this application. If Kestrel is being allocated sockets in a way that is not copacetic to the way IHttpClientFactory/HttpClient is, then they could be stepping on each other.

@ghost ghost added needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration and removed needs-author-action An issue or pull request that requires more info or actions from the author. labels Jan 26, 2022
@tmds
Copy link
Member

tmds commented Jan 26, 2022

Are you talking about running strace as Tomas suggested? I don't know much about this utility yet, but I have access to open a shell into the pods so I can run this. Or are you talking about dotnet-counters or something? I could run that too, I've used it before.

strace requires you to be privileged on the machine.

I mean dotnet-trace.

Could your file descriptor hunch maybe have something to do with how Linux has a lot of interaction with the file system (/proc/ folder and other system files)? Our application does nothing whatsoever with the file system.

Something causes the file descriptor to be registered twice. It could be your code or a 3rd party library. If you're not doing anything special with handles, you should try and figure out what 3rd party library it causing the issue.

I doubt it is .NET or ASP.NET Core because there would be reports about it.

@slidecraft104
Copy link
Author

This is the exception from the Handle is already used by another Socket error/warning:

System.InvalidOperationException: Handle is already used by another Socket.
   at System.Net.Sockets.SocketAsyncEngine.TryRegisterCore(IntPtr socketHandle, SocketAsyncContext context, Error& error)
   at System.Net.Sockets.SocketAsyncEngine.TryRegisterSocket(IntPtr socketHandle, SocketAsyncContext context, SocketAsyncEngine& engine, Error& error)
   at System.Net.Sockets.SocketAsyncContext.TryRegister(Error& error)
   at System.Net.Sockets.SocketAsyncContext.OperationQueue`1.StartAsyncOperation(SocketAsyncContext context, TOperation operation, Int32 observedSequenceNumber, CancellationToken cancellationToken)
   at System.Net.Sockets.SocketAsyncContext.ReceiveAsync(Memory`1 buffer, SocketFlags flags, Int32& bytesReceived, Action`5 callback, CancellationToken cancellationToken)
   at System.Net.Sockets.SocketAsyncEventArgs.DoOperationReceive(SafeSocketHandle handle, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.ReceiveAsync(SocketAsyncEventArgs e, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketReceiver.WaitForDataAsync(Socket socket)
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketConnection.DoReceive()
   at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
   at System.IO.Pipelines.Pipe.ReadAsync(CancellationToken token)
   at System.IO.Pipelines.Pipe.DefaultPipeReader.ReadAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1Connection.BeginRead(ValueTask`1& awaitable)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequestsAsync[TContext](IHttpApplication`1 application)

That doesn't look like anything to do with the file system unless that's under the hood.

@tmds
Copy link
Member

tmds commented Jan 26, 2022

That doesn't look like anything to do with the file system unless that's under the hood.

Yes, this stacktrace doesn't tell us much. We're interested to find out who registered the first Socket for this fd.

@tmds
Copy link
Member

tmds commented Jan 27, 2022

About Handle is already used by another Socket:

There is a related issue (#56750, which may probably be closed). A blog post gets mentioned In that case, the issue disappeared when removing a 3rd party library: https://zblesk.net/blog/aspnetcore-identity-litedb-breaks-on-ubuntu/.

cc @antonfirsov @karelz

About Unknown socket error; ErrorCode: -131074; SocketErrorCode: SocketError; NativeErrorCode: -131074.

Maybe you can make a small reproducer by making HttpClient perform a call against sqs.us-west-2.amazonaws.com:443.

@antonfirsov
Copy link
Member

Having a repro for this would be extremely valuable, this is the 4th report of #56750 if I'm counting well.

@tmds
Copy link
Member

tmds commented Jan 27, 2022

@antonfirsov it doesn't happen often, but when it does, it is a pain to debug. And when I see this, I wonder: can there still be a bug in SocketAsyncEngine...

Thinking out loud.

We could add some envvar which causes the SocketAsyncEngine to track for each SocketAsyncContext the Environment.StackTrace that does the registration. Then, when we throw this exception, we could include that stacktrace.

Or we extend the event source logging so it contains the StackTrace and the user can try match the handle values.

@wfurt
Copy link
Member

wfurt commented Jan 27, 2022

Do you know @tmds its our tracing actually logs the actual OS error or only the translated one? This is reason why I suggested 'strace' as that gives the raw value from kernel.

@tmds
Copy link
Member

tmds commented Jan 27, 2022

Do you know @tmds its our tracing actually logs the actual OS error or only the translated one? This is reason why I suggested 'strace' as that gives the raw value from kernel.

I don't think so. The NativeErrorCode is very weird. I hope the dotnet-trace can help us figure out where in the connect it fails. I assume it's not easy to strace where this app is running due to needed privileges. Also if the error comes from name resolution, it wouldn't show in strace.

@wfurt
Copy link
Member

wfurt commented Jan 27, 2022

For name resolution the tracing should be sufficient AFAIK.

@karelz
Copy link
Member

karelz commented Jan 27, 2022

Triage: This is not the first time we see problems like these. However, we need more info (logs) to make it actionable.
@sliderhouserules are you in position to work with us here or privately to root cause it in your environment and help us improve .NET Core? We would appreciate any help here. Thanks!

@karelz karelz added needs-author-action An issue or pull request that requires more info or actions from the author. and removed untriaged New issue has not been triaged by the area owner needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration labels Jan 27, 2022
@ghost
Copy link

ghost commented Jan 27, 2022

This issue has been marked needs-author-action since it may be missing important information. Please refer to our contribution guidelines for tips on how to report issues effectively.

@karelz karelz added this to the 7.0.0 milestone Jan 27, 2022
@slidecraft104
Copy link
Author

slidecraft104 commented Jan 27, 2022

So... in our testing, the SocketException we can get to for logging on the back-end (Unknown socket error; ErrorCode: -131074; SocketErrorCode: SocketError; NativeErrorCode: -131074 -- that is my log statement) was occurring around 25% to 30% of the time for every outgoing call our code was making. Around 75% or so of the incoming calls hitting Kestrel were logging the warning from the handling pipeline (Handle is already used by another Socket -- I don't know how to get access to those exceptions to be able to log more).

When I shelled into one of the containers and tried running strace, it would attach but then produce no output even though the app was working, both front-end and back-end (and producing errors/warnings). I'm sure I was doing something wrong. dotnet-trace would attach, but almost immediately detach (Detected a potentially broken trace. Continuing with best-efforts to convert the trace [/snip]). If I tried running it over and over, it would eventually work and produce some output, but not for long. Again, I'm sure I was doing something wrong.

So I scoured our code again from top to bottom, left to right and made sure every call was using the IHttpClientFactory. I dug into the AWS source code to make sure every call they are making would use it, just to be sure. I then dug into and found that the main log sink/forwarder we were using is using WebRequest.Create! I got rid of it and worked with our infrastructure to get Kubernetes forwarding logs from STDOUT. However, this didn't get rid of the errors.

Next, I dug into New Relic's .Net Agent source code. We are using RecordMetric and NoticeError quite a bit. I had thought that they were using something like RPC or something from previous trips down that rabbit hole, because their code is confusing. But then I finally found this -- WebRequest.Create... Ugh.

So I commented out every call to the NewRelic Agent, every using, every NuGet reference. The system has been under load for around 3 hours now and the errors have disappeared. (That's a bit of a lie, Kestrel has generated the warning given previously a few times in that three hours.)

tldr; New Relic's .Net Agent is using WebRequest.Create and stripping NR from the app has remedied the problems. I'm going to file an issue with them.

So what's left here that maybe deserves some further scrutiny?

  • Kestrel is generating warnings indicating socket collisions with another (any?) part of an application making outgoing Http calls. (These may not be collisions, this is my interpretation/guess.) I can file an issue over on the aspnet board for this, just let me know.
  • The move from .Net 5 to .Net 6 for this application increased the incidence of these errors/warnings dramatically.
  • Error code -131074 encountered from SocketExceptions isn't part of any TCP error spec that I have found. The message on the exception doesn't include the ErrorCodes at all. Quite unhelpful.

Providing a full repro that doesn't expose custom logic/credentials may be hard for me to get figured out. We are doing heavy interaction with AWS as mentioned. A Kestrel app, with an IHostedService hitting an external resource (GETs, PUTs and POSTs), properly using a shared HttpClient, and then anything using WebRequest instead of a shared HttpClient should recreate this problem under load. Targeting and testing both .Net 5 and .Net 6 should show a difference in frequency of the errors.

Sorry this is so long. Let me know what I can do further.

@ghost ghost added needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration and removed needs-author-action An issue or pull request that requires more info or actions from the author. labels Jan 27, 2022
@wfurt
Copy link
Member

wfurt commented Jan 27, 2022

may be related to #61798. @MihaZupan was looking into that. I don't see direct correlation but they certainly do many unusual things.

@stephentoub stephentoub added documentation Documentation bug or enhancement, does not impact product or test code area-System.Runtime and removed needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration area-System.Net.Http os-linux Linux OS (any supported distro) labels Mar 11, 2022
@ghost
Copy link

ghost commented Mar 11, 2022

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

Issue Details

Description

We have an application based on template dotnet create webapi project template and just adds an IHostedService to do background processing. Kestrel is used in order to be able to answer health checks from Kubernetes, as well as feed new requests into the service to be queued. Our background processing logic involves pretty heavy interaction with AWS resources (SQS, S3, STS), and we are encountering SocketExceptions that have been very difficult to pin down.

The canon guidance to use a static HttpClient instance application-wide does not work well when using the AWS clients in Amazon's SDK packages. The various AWS client constructors, and the config objects you can hand in, do not accept an instance of HttpClient. Instead, you must either rely on their built-in caching of HttpClient instance(s) that are created internally, or you have to provide an implementation that derives from their HttpClientFactory. This is fairly straight-forward if you use IHttpClientFactory in .Net. The Create() method override that you implement simply calls .Create() on an instance of IHttpClientFactory provided via DI.

However, even when providing this HttpClientFactory to all instances of any AWS client that is instantiated anywhere and everywhere in this service, it does not solve the SocketException problem. I will provide the stack trace below, but the properties of the actual SocketException object are extremely unhelpful:

Unknown socket error; ErrorCode: -131074; SocketErrorCode: SocketError; NativeErrorCode: -131074

The twist here is that these errors have only been encountered on Linux/in containers. Extended running tests on Windows cannot reproduce the problem when tested under load.

The other twist is that our Kestrel calls are producing System.InvalidOperationException: Handle is already used by another Socket. errors (they are logged as Warning level) in Kestrel's handling pipeline. It would appear that Kestrel, and the HttpWebRequest pool used underneath IHttpClientFactory are stomping on each other. If I am mischaracterizing the issue and there is a different cause, please let me know.

The fact that the runtime is throwing a SocketException with an error code that isn't even in the spec for TCP errors (nice article here) is the reason I am bringing it to this group. The runtime is burping up what would appear to be the equivalent of the default case in a switch statement.

Any help or guidance here is appreciated.

Reproduction Steps

The basic structure is a Web API project created with dotnet create webapi with an IHostedService doing background processing interacting heavily with AWS resources. I can provide application code privately, as needed, so as to not have to share proprietary/private logic and access keys publicly.

Expected behavior

Interaction with AWS resources from a web application should not cause SocketExceptions.

Actual behavior

We are encountering SocketExceptions that have error codes that aren't even part of the TCP specs:

Unknown socket error; ErrorCode: -131074; SocketErrorCode: SocketError; NativeErrorCode: -131074

Full stack trace:

System.Net.Http.HttpRequestException: Unknown socket error (sqs.us-west-2.amazonaws.com:443)
 ---> System.Net.Sockets.SocketException (0xFFFDFFFE): Unknown socket error
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(HttpRequestMessage request)
   at System.Threading.Tasks.TaskCompletionSourceWithCancellation1.WaitWithCancellationAsync(CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Extensions.Http.PolicyHttpMessageHandler.SendCoreAsync(HttpRequestMessage request, Context context, CancellationToken cancellationToken)
   at Polly.Retry.AsyncRetryEngine.ImplementationAsync[TResult](Func3 action, Context context, CancellationToken cancellationToken, ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates1 shouldRetryResultPredicates, Func5 onRetryAsync, Int32 permittedRetryCount, IEnumerable1 sleepDurationsEnumerable, Func4 sleepDurationProvider, Boolean continueOnCapturedContext)
   at Polly.AsyncPolicy1.ExecuteAsync(Func3 action, Context context, CancellationToken cancellationToken, Boolean continueOnCapturedContext)
   at Microsoft.Extensions.Http.PolicyHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
   at Amazon.Runtime.Internal.HttpHandler1.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.SQS.Internal.ValidationResponseHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
   at <our code starts here>

Regression?

The application in its current form is a .Net 6 solution. In a prior version, it was .Net 5 and the SocketExceptions were very rare if not non-existent.

However, even in the .Net 5 solution Kestrel was throwing the System.InvalidOperationException: Handle is already used by another Socket. warnings when handling basic health check calls.

Known Workarounds

We have implemented heavy retry policies using Polly, which allows the application to move past the errors, but it quite often takes a near complete restart of the background processing logic to clear up the SocketExceptions and allow the application to restart a job and create new connections to the AWS resources being used.

Configuration

  • .NET 6.
  • Ubuntu 20.04 via the base docker images provided directly by Microsoft
  • x64, Kubernetes in AWS EKS

The errors only appear running in containers on Linux.

Other information

N/A

Author: sliderhouserules
Assignees: -
Labels:

documentation, area-System.Runtime

Milestone: 7.0.0

@MMOSimca
Copy link

Also, is there a use case for SafeFileHandle(IntPtr.Zero, true)? You established there's one for SafeFileHandle(IntPtr.Zero, false).

Given how much the questionable documentation has spread around, it would be great to have a code solution. I'd be happy to write something, but it does sound like based on this conversation that it would just be rejected.

@tmds
Copy link
Member

tmds commented Mar 11, 2022

Is there anything further we should do about the fact that Kestrel was writing requests with the wrong output stream when all of its input streams were closed?

If it is caused by SafeFileHandle(IntPtr.Zero, true): no.
You musn't set ownsHandle to true for file descriptors you don't own.

Also, is there a use case for SafeFileHandle(IntPtr.Zero, true)? You established there's one for SafeFileHandle(IntPtr.Zero, false).

In practice, I don't think so.

Given how much the questionable documentation has spread around, it would be great to have a code solution.

You mean a better example for the IDisposable documentation?

The handle = new SafeFileHandle(IntPtr.Zero, true) is meant to represent an IDisposable that gets disposed under if (disposing).
It could be replace by something else that is disposable. It doesn't even need to be a SafeHandle. It could for example be fs = File.OpenWrite(Path.GetTempFileName()).

@MMOSimca
Copy link

Given how much the questionable documentation has spread around, it would be great to have a code solution.

You mean a better example for the IDisposable documentation?

The handle = new SafeFileHandle(IntPtr.Zero, true) is meant to represent an IDisposable that gets disposed under if (disposing). It could be replace by something else that is disposable. It doesn't even need to be a SafeHandle. It could for example be fs = File.OpenWrite(Path.GetTempFileName()).

I mean in the constructor for SafeFileHandle, if the first parameter is 0 and the second parameter is true, throw an exception. Or can you do warnings like that (based on parameters)? I'm looking through private repositories I have access to and I see this in 1 other unrelated project, which is not great.

I agree with you that the documentation for IDisposable shouldn't mention SafeFileHandle at all. Very dangerous function calls don't have a place anywhere near a 'best practices how to implement IDisposable tutorial'. I see it copied around the internet to other places on how to implement the IDisposable pattern, and it's like they spread around a kind of knowledge infection where they are instead teaching how to ruin your program on Linux. The irony level for a code example teaching best practices is through the roof. I'm going around to a few of these places and pointing it out.

Considering that the 2nd example doesn't even contain a disposable object (it's just the code needed to dispose one if one did exist), I don't know that you need to have any representation of a disposable object at all rather than like a comment saying that this is where you'd place one. Do you have a preference? Is it standard to include a representative example line in docs like this or just use a comment (or nothing)?

@tmds
Copy link
Member

tmds commented Mar 25, 2022

Now that we've identified new SafeFileHandle(IntPtr.Zero, true); as a source of this problem.
Is there still an open issue that needs to be investigated further? Or can this issue be closed?

@slidecraft104
Copy link
Author

The SafeFileHandle stuff is not my issue, no. We are using a third-party document processing engine that does use unmanaged code, and I do need to verify 100% that they are not actually doing this. But until then, we need to consider that my issue is caused by something else and I still need to do a thorough investigation. My time at work has not been able to put this up in the priority stack high enough to get to that just yet. I apologize. Can we please leave this issue open a bit longer?

@tmds
Copy link
Member

tmds commented Mar 25, 2022

Yes, we'll keep it open until you had some time to investigate and check whether the root cause is also the IntPtr.Zero SafeFileHandle.

@SpringHgui
Copy link

The problem remains in .net6

@antonfirsov
Copy link
Member

@SpringHgui is it possible that your code or a library you rely on instantiates a new SafeFileHandle(IntPtr.Zero, true) somewhere? For example see fabian-blum/AspNetCore.Identity.LiteDB#14 and Marilyth/MopsBot-2.0#74

@SpringHgui
Copy link

The problem remains in .net8

@wfurt
Copy link
Member

wfurt commented Jun 13, 2024

do you have repro you can share @SpringHgui ? The linked repo above has way too much stuff. Alternatively can you do the strace or get detailed diagnostic logs?

@SpringHgui
Copy link

do you have repro you can share @SpringHgui ? The linked repo above has way too much stuff. Alternatively can you do the strace or get detailed diagnostic logs?

I encountered this error because I used the websocket-sharp library, in this library I reported an error, the startup project was upgraded from .net6 to .net8, it still exists, and the specific location is not located at present, and the windwos server is replaced, and this problem no longer occurs

@icefire1
Copy link

I encountered this socket error when working on a MAUI app. For me the error only happened on some old Android devices and not consistently. What seemed to fix it for me was to explicitly close my socket instead of relying on dispose being called for me.

Broken code

private static async Task<bool> ScanPort(string ipAddress, int port, TimeSpan timeout, CancellationToken token)
{
    using var tcpClient = new TcpClient();
    using var cts = CancellationTokenSource.CreateLinkedTokenSource(token);
    cts.CancelAfter(timeout);

    await tcpClient.ConnectAsync(ipAddress, port, cts.Token);
    return tcpClient.Connected;
}

Working code

private static async Task<bool> ScanPort(string ipAddress, int port, TimeSpan timeout, CancellationToken token)
{
    using var cts = CancellationTokenSource.CreateLinkedTokenSource(token);
    cts.CancelAfter(timeout);

    using var tcpClient = new TcpClient();
    await tcpClient.ConnectAsync(ipAddress, port, cts.Token);
    var didConnect = tcpClient.Connected;
    tcpClient.Close();
    return didConnect;
}

@wfurt
Copy link
Member

wfurt commented Jul 26, 2024

interesting. how many destinations are you trying to scan @icefire1 ? I'm wondering if you run out of max open file descriptors in this case...

@icefire1
Copy link

icefire1 commented Jul 26, 2024

@wfurt difficult to say exactly as it happened inconsistently, but I would guess somewhere around 10-40 scans over a duration of a few seconds to a few minutes.

Perhaps it's because too many sockets where opened at once. I would add, however, that I cannot replicate it by simply opening a lot of socket like so:

var clients = new List<TcpClient>();
for (int i = 0; i < 100000; i++)
{
	clients.Add(new TcpClient());
}

Above code would indeed give me an exception, but it would be ErrorCode 23 instead. With a message
"File table overflow". I tested the sample code on both a new and an old device (which gave me the unknown socket error).

@wfurt
Copy link
Member

wfurt commented Jul 26, 2024

Makes me wonder if it is related to the CancellationTokenSource.CreateLinkedTokenSource and cancellation in general.

@KaeTar
Copy link

KaeTar commented Feb 19, 2025

Hey guys. I am running into this exact issue. I have an app that I migrated from Xamarin to .net MAUI. I am on .net 9.0.200 currently with maui 9.0.40. I have tried .net 8 as well. My app uses quite a bit of HttpClient via the HttpClientFactory. I also use the Preference API and read and write some json files as well. Something in the app is closing FD 0 (stdin). The next time something opens a file descriptor (httpclient, File API, Preference Api, Sqlite, etc...) it will pick up FD 0. When later it is closed, the app container OS Watchdog sends a SIGKILL to the process leaving me with no information to troubleshoot. If it is HttpClient that picks it up with HttpSocketsHandler it manifests in the Unkown Socket Error but also sometimes directly ends in a SIGKILL. Being how this is compiled and ran on iOS and Android in a signed package makes it even more abstract to troubleshoot. Can you guys provide any guidance on how to run this down. I have spent months trying to figure this out. I am at a loss trying to figure out "What" is closing FD0. It is almost always in the finalizer thread. Here are some examples of what I see:

HttpClient w/ HttpSocketsHandler

`System.AggregateException: One or more errors occurred. (Unknown socket error (ws.ivicentral.com:443))
 ---> System.Net.Http.HttpRequestException: Unknown socket error (ws.ivicentral.com:443)
 ---> System.Net.Sockets.SocketException (0xFFFDFFFE): Unknown socket error
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|285_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.InjectNewHttp11ConnectionAsync(QueueItem queueItem)
   at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.<WaitWithCancellationAsync>d__1[[System.Net.Http.HttpConnection, System.Net.Http, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext()
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.DecompressionHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.<SendCoreAsync>g__Core|4_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken)
   at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.<SendCoreAsync>g__Core|4_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at IVI.Central.MAUI.IVICentral.PanelClient.GetPanelDetailWrappedAsync(Guid panelId, CancellationToken cancellationToken) in /Users/paulaicher/Development/IVI/IVI.Central.MAUI/IVI.Central.MAUI/Connected Services/IVICentral/IVICentralClient.Generated.cs:line 1960
   --- End of inner exception stack trace ---`

Randomly I see this behavior where iOS kills the app pid due to:

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Incident Identifier: 01719029-32E4-4280-A229-21FD1FF76159
CrashReporter Key:   8E966C1A-6D14-D704-0311-05CB556DCE89
Hardware Model:      Mac15,9
Process:             IVI.Central.MAUI [20422]
Path:                /Users/USER/Library/Developer/CoreSimulator/Devices/F406D674-D2BC-40B6-B8D8-E2BAA3C42898/data/Containers/Bundle/Application/78083837-9ED6-4934-AF7B-C291DF574733/IVI.Central.MAUI.app/IVI.Central.MAUI
Identifier:          com.us.ivi.IVICentral
Version:             2.0 (111111)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd_sim [95937]
Coalition:           com.apple.CoreSimulator.SimDevice.F406D674-D2BC-40B6-B8D8-E2BAA3C42898 [431285]
Responsible Process: SimulatorTrampoline [2343]

Date/Time:           2025-02-13 09:57:29.6353 -0700
Launch Time:         2025-02-13 09:57:19.0682 -0700
OS Version:          macOS 15.3 (24D60)
Release Type:        User
Report Version:      104

Exception Type:  EXC_GUARD (SIGKILL)
Exception Subtype: GUARD_TYPE_FD
Exception Message:  CLOSE on file descriptor 0 (guarded with 0x08fd4dbfade2dead)
Exception Codes: 0x0000000000000000, 0x08fd4dbfade2dead
Termination Reason: GUARD 4611686022722355200 

Triggered by Thread:  3

Thread 0:: tid_103 Dispatch queue: com.apple.main-thread
0   libmonosgen-2.0.dylib         	       0x1057b9428 dn_simdhash_ght_insert_replace + 16
1   libmonosgen-2.0.dylib         	       0x1057df08c mono_class_inflate_generic_method_full_checked + 1372
2   libmonosgen-2.0.dylib         	       0x1057f1e6c mono_class_setup_vtable_general + 992
3   libmonosgen-2.0.dylib         	       0x1057f19f4 mono_class_setup_vtable_full + 396
4   libmonosgen-2.0.dylib         	       0x105779998 get_virtual_method + 52
5   libmonosgen-2.0.dylib         	       0x10577944c get_virtual_method_fast + 376
6   libmonosgen-2.0.dylib         	       0x10576f48c mono_interp_exec_method + 3112
7   libmonosgen-2.0.dylib         	       0x10576ce34 interp_runtime_invoke + 244
8   libmonosgen-2.0.dylib         	       0x105688a14 mono_jit_runtime_invoke + 1244
9   libmonosgen-2.0.dylib         	       0x105845f08 mono_runtime_invoke_checked + 148
10  libmonosgen-2.0.dylib         	       0x105849ae0 mono_runtime_invoke + 540
11  libxamarin-dotnet-debug.dylib 	       0x105375c08 xamarin_invoke_trampoline + 5516
12  libxamarin-dotnet-debug.dylib 	       0x10537dd2c xamarin_arch_trampoline + 148
13  libxamarin-dotnet-debug.dylib 	       0x10537eb10 xamarin_arm64_common_trampoline + 64
14  DXListView                    	       0x104b61884 -[DXContainerItemViewProvider getViewByIndex:andViewType:] + 44
15  DXListView                    	       0x104b5ee84 -[DXAsyncViewAdapter getViewByIndex:andViewType:] + 252
16  DXListView                    	       0x104b5e810 -[ComplexVerticalItemsLayout createElementByIndex:forIndex:forViewtype:andKnownSize:andItemSize:] + 64
17  DXListView                    	       0x104b54ddc -[ComplexItemsLayout createContainer:andStartIndex:andFromStartToEnd:andViewport:andContainerStart:andAvgItemSize:andItemCount:andIsGrouped:andAddInLayout:forceSyncUpdate:] + 564
18  DXListView                    	       0x104b55dec -[ComplexItemsLayout layoutFromStartToEnd:andAverageItemSize:andItemCount:andIsGrouped:] + 384
19  DXListView                    	       0x104b572ac -[ComplexItemsLayout layoutSubviewsCore:] + 892
20  DXListView                    	       0x104b56a1c -[ComplexItemsLayout layoutSubviews:] + 80
21  DXListView                    	       0x104b5de60 -[VirtualScrollView layoutSubviews] + 356
22  UIKitCore                     	       0x1860a3418 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2404
23  QuartzCore                    	       0x18b335624 CA::Layer::layout_if_needed(CA::Transaction*) + 432
24  QuartzCore                    	       0x18b3403f8 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 124
25  QuartzCore                    	       0x18b272430 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 464
26  QuartzCore                    	       0x18b2a0c70 CA::Transaction::commit() + 652
27  QuartzCore                    	       0x18b2a21c4 CA::Transaction::flush_as_runloop_observer(bool) + 68
28  UIKitCore                     	       0x185b302fc _UIApplicationFlushCATransaction + 48
29  UIKitCore                     	       0x185a60eb4 __setupUpdateSequence_block_invoke_2 + 352
30  UIKitCore                     	       0x1850a5cec _UIUpdateSequenceRun + 76
31  UIKitCore                     	       0x185a60858 schedulerStepScheduledMainSection + 168
32  UIKitCore                     	       0x185a5fc90 runloopSourceCallback + 80
33  CoreFoundation                	       0x18041d294 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
34  CoreFoundation                	       0x18041d1dc __CFRunLoopDoSource0 + 172
35  CoreFoundation                	       0x18041c99c __CFRunLoopDoSources0 + 324
36  CoreFoundation                	       0x180416e84 __CFRunLoopRun + 788
37  CoreFoundation                	       0x1804166f4 CFRunLoopRunSpecific + 552
38  GraphicsServices              	       0x1905e5b10 GSEventRunModal + 160
39  UIKitCore                     	       0x185b319dc -[UIApplication _run] + 796
40  UIKitCore                     	       0x185b35bd4 UIApplicationMain + 124
41  libxamarin-dotnet-debug.dylib 	       0x10533d288 xamarin_UIApplicationMain + 60
42  libmonosgen-2.0.dylib         	       0x10577b754 do_icall + 316
43  libmonosgen-2.0.dylib         	       0x105779c78 do_icall_wrapper + 356
44  libmonosgen-2.0.dylib         	       0x10576f36c mono_interp_exec_method + 2824
45  libmonosgen-2.0.dylib         	       0x10576ce34 interp_runtime_invoke + 244
46  libmonosgen-2.0.dylib         	       0x105688a14 mono_jit_runtime_invoke + 1244
47  libmonosgen-2.0.dylib         	       0x105845f08 mono_runtime_invoke_checked + 148
48  libmonosgen-2.0.dylib         	       0x10584d168 mono_runtime_exec_main_checked + 116
49  libmonosgen-2.0.dylib         	       0x1056dba6c mono_jit_exec + 364
50  libxamarin-dotnet-debug.dylib 	       0x10537dbac xamarin_main + 2312
51  IVI.Central.MAUI              	       0x103e6b768 main + 64 (main.arm64.mm:79)
52  dyld_sim                      	       0x104de5410 start_sim + 20
53  dyld                          	       0x104cc2274 start + 2840

Thread 1:
0   libsystem_kernel.dylib        	       0x105119490 __recvfrom + 8
1   libxamarin-dotnet-debug.dylib 	       0x10537ba40 recv_uninterrupted(int, void*, unsigned long) + 72
2   libxamarin-dotnet-debug.dylib 	       0x10537ad10 monotouch_process_connection + 116
3   libxamarin-dotnet-debug.dylib 	       0x10537ac30 monotouch_connect_wifi + 3620
4   libxamarin-dotnet-debug.dylib 	       0x105379508 monotouch_configure_debugging + 2960
5   libxamarin-dotnet-debug.dylib 	       0x105364570 -[XamarinCocoaThreadInitializer entryPoint:] + 76
6   Foundation                    	       0x180f46280 __NSThread__start__ + 720
7   libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
8   libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 2:: SGen worker
0   libmonosgen-2.0.dylib         	       0x1058d0e2c sweep_block + 440
1   libmonosgen-2.0.dylib         	       0x1058d1ba4 sweep_blocks_job_func + 188
2   libmonosgen-2.0.dylib         	       0x1058e0f20 thread_func + 544
3   libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
4   libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 3 Crashed:: Finalizer
0   libsystem_kernel.dylib        	       0x105115e80 close + 8
1   libmonosgen-2.0.dylib         	       0x10577b6a4 do_icall + 140
2   libmonosgen-2.0.dylib         	       0x105779c78 do_icall_wrapper + 356
3   libmonosgen-2.0.dylib         	       0x10576f36c mono_interp_exec_method + 2824
4   libmonosgen-2.0.dylib         	       0x10576c628 interp_entry_from_trampoline + 664
5   IVI.Central.MAUI              	       0x10297d970 native_to_interp_trampoline + 112
6   libmonosgen-2.0.dylib         	       0x105884908 mono_gc_run_finalize + 588
7   libmonosgen-2.0.dylib         	       0x1058ad3cc sgen_gc_invoke_finalizers + 264
8   libmonosgen-2.0.dylib         	       0x105886414 finalizer_thread + 1204
9   libmonosgen-2.0.dylib         	       0x10585ef08 start_wrapper + 340
10  libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
11  libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 4:: Debugger agent
0   libsystem_kernel.dylib        	       0x105119490 __recvfrom + 8
1   libxamarin-dotnet-debug.dylib 	       0x10537ba40 recv_uninterrupted(int, void*, unsigned long) + 72
2   libxamarin-dotnet-debug.dylib 	       0x10537b9c4 sdb_recv(void*, unsigned long) + 56
3   libmono-component-debugger.dylib	       0x104f4cd1c mono_debugger_agent_receive_and_process_command + 220
4   libmono-component-debugger.dylib	       0x104f4f878 debugger_thread + 592
5   libmonosgen-2.0.dylib         	       0x10585ef08 start_wrapper + 340
6   libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
7   libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 5:: com.apple.uikit.eventfetch-thread
0   libsystem_kernel.dylib        	       0x105115390 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	       0x1051266e0 mach_msg2_internal + 76
2   libsystem_kernel.dylib        	       0x10511d4f4 mach_msg_overwrite + 536
3   libsystem_kernel.dylib        	       0x1051156cc mach_msg + 20
4   CoreFoundation                	       0x18041cad0 __CFRunLoopServiceMachPort + 156
5   CoreFoundation                	       0x180416ff8 __CFRunLoopRun + 1160
6   CoreFoundation                	       0x1804166f4 CFRunLoopRunSpecific + 552
7   Foundation                    	       0x180f1f438 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 208
8   Foundation                    	       0x180f1f658 -[NSRunLoop(NSRunLoop) runUntilDate:] + 60
9   UIKitCore                     	       0x185bdf284 -[UIEventFetcher threadMain] + 404
10  Foundation                    	       0x180f46280 __NSThread__start__ + 720
11  libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
12  libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 6:: tid_5e03
0   libsystem_pthread.dylib       	       0x10517e92c start_wqthread + 0

Thread 7:: tid_7403
0   libsystem_pthread.dylib       	       0x10517e92c start_wqthread + 0

Thread 8:
0   libsystem_pthread.dylib       	       0x10517e92c start_wqthread + 0

Thread 9:
0   libsystem_pthread.dylib       	       0x10517e92c start_wqthread + 0

Thread 10:
0   libsystem_pthread.dylib       	       0x10517e92c start_wqthread + 0

Thread 11:: tid_6b03
0   libsystem_pthread.dylib       	       0x10517e92c start_wqthread + 0

Thread 12:: .NET TP Worker
0   libmonosgen-2.0.dylib         	       0x1057781d4 mono_interp_exec_method + 39280
1   libmonosgen-2.0.dylib         	       0x10576ce34 interp_runtime_invoke + 244
2   libmonosgen-2.0.dylib         	       0x105688a14 mono_jit_runtime_invoke + 1244
3   libmonosgen-2.0.dylib         	       0x105845f08 mono_runtime_invoke_checked + 148
4   libmonosgen-2.0.dylib         	       0x10585eff4 start_wrapper + 576
5   libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
6   libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 13:: .NET TP Gate
0   libsystem_kernel.dylib        	       0x10511882c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x105183cc4 _pthread_cond_wait + 1236
2   libSystem.Native.dylib        	       0x104c013f4 SystemNative_LowLevelMonitor_TimedWait + 104
3   libmonosgen-2.0.dylib         	       0x10577b6c8 do_icall + 176
4   libmonosgen-2.0.dylib         	       0x105779c78 do_icall_wrapper + 356
5   libmonosgen-2.0.dylib         	       0x10576f36c mono_interp_exec_method + 2824
6   libmonosgen-2.0.dylib         	       0x10576ce34 interp_runtime_invoke + 244
7   libmonosgen-2.0.dylib         	       0x105688a14 mono_jit_runtime_invoke + 1244
8   libmonosgen-2.0.dylib         	       0x105845f08 mono_runtime_invoke_checked + 148
9   libmonosgen-2.0.dylib         	       0x10585eff4 start_wrapper + 576
10  libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
11  libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 14:: .NET Timer
0   libsystem_kernel.dylib        	       0x10511882c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x105183cc4 _pthread_cond_wait + 1236
2   libSystem.Native.dylib        	       0x104c013f4 SystemNative_LowLevelMonitor_TimedWait + 104
3   libmonosgen-2.0.dylib         	       0x10577b6c8 do_icall + 176
4   libmonosgen-2.0.dylib         	       0x105779c78 do_icall_wrapper + 356
5   libmonosgen-2.0.dylib         	       0x10576f36c mono_interp_exec_method + 2824
6   libmonosgen-2.0.dylib         	       0x10576ce34 interp_runtime_invoke + 244
7   libmonosgen-2.0.dylib         	       0x105688a14 mono_jit_runtime_invoke + 1244
8   libmonosgen-2.0.dylib         	       0x105845f08 mono_runtime_invoke_checked + 148
9   libmonosgen-2.0.dylib         	       0x10585eff4 start_wrapper + 576
10  libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
11  libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 15:: PanelTendererWorker6
0   libsystem_kernel.dylib        	       0x10511882c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x105183c98 _pthread_cond_wait + 1192
2   libmonosgen-2.0.dylib         	       0x1057c3494 mono_os_cond_timedwait + 208
3   libmonosgen-2.0.dylib         	       0x105863f98 mono_w32handle_timedwait_signal_handle + 336
4   libmonosgen-2.0.dylib         	       0x105863d50 mono_w32handle_wait_one + 772
5   libmonosgen-2.0.dylib         	       0x1058877f0 ves_icall_System_Threading_Monitor_Monitor_wait + 292
6   libmonosgen-2.0.dylib         	       0x10581347c ves_icall_System_Threading_Monitor_Monitor_wait_raw + 88
7   libmonosgen-2.0.dylib         	       0x10577b6f4 do_icall + 220
8   libmonosgen-2.0.dylib         	       0x105779cb0 do_icall_wrapper + 412
9   libmonosgen-2.0.dylib         	       0x10576f36c mono_interp_exec_method + 2824
10  libmonosgen-2.0.dylib         	       0x10576ce34 interp_runtime_invoke + 244
11  libmonosgen-2.0.dylib         	       0x105688a14 mono_jit_runtime_invoke + 1244
12  libmonosgen-2.0.dylib         	       0x105845f08 mono_runtime_invoke_checked + 148
13  libmonosgen-2.0.dylib         	       0x10585eff4 start_wrapper + 576
14  libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
15  libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 16:: PanelTendererWorker6
0   libsystem_kernel.dylib        	       0x10511882c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x105183c98 _pthread_cond_wait + 1192
2   libmonosgen-2.0.dylib         	       0x1057c3494 mono_os_cond_timedwait + 208
3   libmonosgen-2.0.dylib         	       0x105863f98 mono_w32handle_timedwait_signal_handle + 336
4   libmonosgen-2.0.dylib         	       0x105863d50 mono_w32handle_wait_one + 772
5   libmonosgen-2.0.dylib         	       0x1058877f0 ves_icall_System_Threading_Monitor_Monitor_wait + 292
6   libmonosgen-2.0.dylib         	       0x10581347c ves_icall_System_Threading_Monitor_Monitor_wait_raw + 88
7   libmonosgen-2.0.dylib         	       0x10577b6f4 do_icall + 220
8   libmonosgen-2.0.dylib         	       0x105779cb0 do_icall_wrapper + 412
9   libmonosgen-2.0.dylib         	       0x10576f36c mono_interp_exec_method + 2824
10  libmonosgen-2.0.dylib         	       0x10576ce34 interp_runtime_invoke + 244
11  libmonosgen-2.0.dylib         	       0x105688a14 mono_jit_runtime_invoke + 1244
12  libmonosgen-2.0.dylib         	       0x105845f08 mono_runtime_invoke_checked + 148
13  libmonosgen-2.0.dylib         	       0x10585eff4 start_wrapper + 576
14  libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
15  libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 17:: PanelTendererWorker6
0   libsystem_kernel.dylib        	       0x10511882c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x105183c98 _pthread_cond_wait + 1192
2   libmonosgen-2.0.dylib         	       0x1057c3494 mono_os_cond_timedwait + 208
3   libmonosgen-2.0.dylib         	       0x105863f98 mono_w32handle_timedwait_signal_handle + 336
4   libmonosgen-2.0.dylib         	       0x105863d50 mono_w32handle_wait_one + 772
5   libmonosgen-2.0.dylib         	       0x1058877f0 ves_icall_System_Threading_Monitor_Monitor_wait + 292
6   libmonosgen-2.0.dylib         	       0x10581347c ves_icall_System_Threading_Monitor_Monitor_wait_raw + 88
7   libmonosgen-2.0.dylib         	       0x10577b6f4 do_icall + 220
8   libmonosgen-2.0.dylib         	       0x105779cb0 do_icall_wrapper + 412
9   libmonosgen-2.0.dylib         	       0x10576f36c mono_interp_exec_method + 2824
10  libmonosgen-2.0.dylib         	       0x10576ce34 interp_runtime_invoke + 244
11  libmonosgen-2.0.dylib         	       0x105688a14 mono_jit_runtime_invoke + 1244
12  libmonosgen-2.0.dylib         	       0x105845f08 mono_runtime_invoke_checked + 148
13  libmonosgen-2.0.dylib         	       0x10585eff4 start_wrapper + 576
14  libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
15  libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 18:: PanelTendererWorker6
0   libsystem_kernel.dylib        	       0x10511882c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x105183c98 _pthread_cond_wait + 1192
2   libmonosgen-2.0.dylib         	       0x1057c3494 mono_os_cond_timedwait + 208
3   libmonosgen-2.0.dylib         	       0x105863f98 mono_w32handle_timedwait_signal_handle + 336
4   libmonosgen-2.0.dylib         	       0x105863d50 mono_w32handle_wait_one + 772
5   libmonosgen-2.0.dylib         	       0x1058877f0 ves_icall_System_Threading_Monitor_Monitor_wait + 292
6   libmonosgen-2.0.dylib         	       0x10581347c ves_icall_System_Threading_Monitor_Monitor_wait_raw + 88
7   libmonosgen-2.0.dylib         	       0x10577b6f4 do_icall + 220
8   libmonosgen-2.0.dylib         	       0x105779cb0 do_icall_wrapper + 412
9   libmonosgen-2.0.dylib         	       0x10576f36c mono_interp_exec_method + 2824
10  libmonosgen-2.0.dylib         	       0x10576ce34 interp_runtime_invoke + 244
11  libmonosgen-2.0.dylib         	       0x105688a14 mono_jit_runtime_invoke + 1244
12  libmonosgen-2.0.dylib         	       0x105845f08 mono_runtime_invoke_checked + 148
13  libmonosgen-2.0.dylib         	       0x10585eff4 start_wrapper + 576
14  libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
15  libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 19:: PanelTendererWorker6
0   libsystem_kernel.dylib        	       0x10511882c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x105183c98 _pthread_cond_wait + 1192
2   libmonosgen-2.0.dylib         	       0x1057c3494 mono_os_cond_timedwait + 208
3   libmonosgen-2.0.dylib         	       0x105863f98 mono_w32handle_timedwait_signal_handle + 336
4   libmonosgen-2.0.dylib         	       0x105863d50 mono_w32handle_wait_one + 772
5   libmonosgen-2.0.dylib         	       0x1058877f0 ves_icall_System_Threading_Monitor_Monitor_wait + 292
6   libmonosgen-2.0.dylib         	       0x10581347c ves_icall_System_Threading_Monitor_Monitor_wait_raw + 88
7   libmonosgen-2.0.dylib         	       0x10577b6f4 do_icall + 220
8   libmonosgen-2.0.dylib         	       0x105779cb0 do_icall_wrapper + 412
9   libmonosgen-2.0.dylib         	       0x10576f36c mono_interp_exec_method + 2824
10  libmonosgen-2.0.dylib         	       0x10576ce34 interp_runtime_invoke + 244
11  libmonosgen-2.0.dylib         	       0x105688a14 mono_jit_runtime_invoke + 1244
12  libmonosgen-2.0.dylib         	       0x105845f08 mono_runtime_invoke_checked + 148
13  libmonosgen-2.0.dylib         	       0x10585eff4 start_wrapper + 576
14  libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
15  libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 20:: .NET TP Worker
0   libsystem_kernel.dylib        	       0x10511882c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x105183c98 _pthread_cond_wait + 1192
2   libmonosgen-2.0.dylib         	       0x1057c346c mono_os_cond_timedwait + 168
3   libmonosgen-2.0.dylib         	       0x1057c7828 mono_lifo_semaphore_timed_wait + 268
4   libmonosgen-2.0.dylib         	       0x10577b6c8 do_icall + 176
5   libmonosgen-2.0.dylib         	       0x105779cb0 do_icall_wrapper + 412
6   libmonosgen-2.0.dylib         	       0x10576f36c mono_interp_exec_method + 2824
7   libmonosgen-2.0.dylib         	       0x10576ce34 interp_runtime_invoke + 244
8   libmonosgen-2.0.dylib         	       0x105688a14 mono_jit_runtime_invoke + 1244
9   libmonosgen-2.0.dylib         	       0x105845f08 mono_runtime_invoke_checked + 148
10  libmonosgen-2.0.dylib         	       0x10585eff4 start_wrapper + 576
11  libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
12  libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 21:: .NET Sockets
0   libsystem_kernel.dylib        	       0x10511ae84 kevent + 8
1   libSystem.Native.dylib        	       0x104bff590 SystemNative_WaitForSocketEvents + 80
2   libmonosgen-2.0.dylib         	       0x10577b6f4 do_icall + 220
3   libmonosgen-2.0.dylib         	       0x105779c78 do_icall_wrapper + 356
4   libmonosgen-2.0.dylib         	       0x10576f36c mono_interp_exec_method + 2824
5   libmonosgen-2.0.dylib         	       0x10576ce34 interp_runtime_invoke + 244
6   libmonosgen-2.0.dylib         	       0x105688a14 mono_jit_runtime_invoke + 1244
7   libmonosgen-2.0.dylib         	       0x105845f08 mono_runtime_invoke_checked + 148
8   libmonosgen-2.0.dylib         	       0x10585eff4 start_wrapper + 576
9   libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
10  libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 22:: .NET Sockets
0   libsystem_kernel.dylib        	       0x10511ae84 kevent + 8
1   libSystem.Native.dylib        	       0x104bff590 SystemNative_WaitForSocketEvents + 80
2   libmonosgen-2.0.dylib         	       0x10577b6f4 do_icall + 220
3   libmonosgen-2.0.dylib         	       0x105779c78 do_icall_wrapper + 356
4   libmonosgen-2.0.dylib         	       0x10576f36c mono_interp_exec_method + 2824
5   libmonosgen-2.0.dylib         	       0x10576ce34 interp_runtime_invoke + 244
6   libmonosgen-2.0.dylib         	       0x105688a14 mono_jit_runtime_invoke + 1244
7   libmonosgen-2.0.dylib         	       0x105845f08 mono_runtime_invoke_checked + 148
8   libmonosgen-2.0.dylib         	       0x10585eff4 start_wrapper + 576
9   libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
10  libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 23:: .NET TP Worker
0   libsystem_kernel.dylib        	       0x10511882c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x105183c98 _pthread_cond_wait + 1192
2   libmonosgen-2.0.dylib         	       0x1057c346c mono_os_cond_timedwait + 168
3   libmonosgen-2.0.dylib         	       0x1057c7828 mono_lifo_semaphore_timed_wait + 268
4   libmonosgen-2.0.dylib         	       0x10577b6c8 do_icall + 176
5   libmonosgen-2.0.dylib         	       0x105779cb0 do_icall_wrapper + 412
6   libmonosgen-2.0.dylib         	       0x10576f36c mono_interp_exec_method + 2824
7   libmonosgen-2.0.dylib         	       0x10576ce34 interp_runtime_invoke + 244
8   libmonosgen-2.0.dylib         	       0x105688a14 mono_jit_runtime_invoke + 1244
9   libmonosgen-2.0.dylib         	       0x105845f08 mono_runtime_invoke_checked + 148
10  libmonosgen-2.0.dylib         	       0x10585eff4 start_wrapper + 576
11  libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
12  libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 24:: .NET TP Worker
0   libsystem_kernel.dylib        	       0x10511882c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x105183c98 _pthread_cond_wait + 1192
2   libmonosgen-2.0.dylib         	       0x1057c346c mono_os_cond_timedwait + 168
3   libmonosgen-2.0.dylib         	       0x1057c7828 mono_lifo_semaphore_timed_wait + 268
4   libmonosgen-2.0.dylib         	       0x10577b6c8 do_icall + 176
5   libmonosgen-2.0.dylib         	       0x105779cb0 do_icall_wrapper + 412
6   libmonosgen-2.0.dylib         	       0x10576f36c mono_interp_exec_method + 2824
7   libmonosgen-2.0.dylib         	       0x10576ce34 interp_runtime_invoke + 244
8   libmonosgen-2.0.dylib         	       0x105688a14 mono_jit_runtime_invoke + 1244
9   libmonosgen-2.0.dylib         	       0x105845f08 mono_runtime_invoke_checked + 148
10  libmonosgen-2.0.dylib         	       0x10585eff4 start_wrapper + 576
11  libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
12  libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 25:: .NET TP Worker
0   libsystem_kernel.dylib        	       0x10511882c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x105183c98 _pthread_cond_wait + 1192
2   libmonosgen-2.0.dylib         	       0x1057c346c mono_os_cond_timedwait + 168
3   libmonosgen-2.0.dylib         	       0x1057c7828 mono_lifo_semaphore_timed_wait + 268
4   libmonosgen-2.0.dylib         	       0x10577b6c8 do_icall + 176
5   libmonosgen-2.0.dylib         	       0x105779cb0 do_icall_wrapper + 412
6   libmonosgen-2.0.dylib         	       0x10576f36c mono_interp_exec_method + 2824
7   libmonosgen-2.0.dylib         	       0x10576ce34 interp_runtime_invoke + 244
8   libmonosgen-2.0.dylib         	       0x105688a14 mono_jit_runtime_invoke + 1244
9   libmonosgen-2.0.dylib         	       0x105845f08 mono_runtime_invoke_checked + 148
10  libmonosgen-2.0.dylib         	       0x10585eff4 start_wrapper + 576
11  libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
12  libsystem_pthread.dylib       	       0x10517e940 thread_start + 8

Thread 26:: com.apple.NSURLConnectionLoader
0   libsystem_kernel.dylib        	       0x105115390 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	       0x1051266e0 mach_msg2_internal + 76
2   libsystem_kernel.dylib        	       0x10511d4f4 mach_msg_overwrite + 536
3   libsystem_kernel.dylib        	       0x1051156cc mach_msg + 20
4   CoreFoundation                	       0x18041cad0 __CFRunLoopServiceMachPort + 156
5   CoreFoundation                	       0x180416ff8 __CFRunLoopRun + 1160
6   CoreFoundation                	       0x1804166f4 CFRunLoopRunSpecific + 552
7   CFNetwork                     	       0x184a03d64 +[__CFN_CoreSchedulingSetRunnable _run:] + 372
8   Foundation                    	       0x180f46280 __NSThread__start__ + 720
9   libsystem_pthread.dylib       	       0x1051836f8 _pthread_start + 104
10  libsystem_pthread.dylib       	       0x10517e940 thread_start + 8


Thread 3 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000001   x1: 0x0000000000000000   x2: 0x0000000168c00200   x3: 0x0000000168c00210
    x4: 0x0000000104bf80e0   x5: 0x0000000000000000   x6: 0x0000000000000000   x7: 0x000000016d846a54
    x8: 0x0000000000000003   x9: 0x00000001058f53d9  x10: 0x000000010577b69c  x11: 0x000000000000000b
   x12: 0x000000016d8468d0  x13: 0x0000000105779c58  x14: 0x0000000000000000  x15: 0x0000000000000000
   x16: 0x0000000000000006  x17: 0x0000000000004000  x18: 0x0000000000000000  x19: 0x0000000168c00200
   x20: 0x00000001060b09a8  x21: 0x0000000000000000  x22: 0x0000000104bf80e0  x23: 0x0000000168c00210
   x24: 0x0000000000000003  x25: 0x0000000000000225  x26: 0x0000600002c0ae48  x27: 0x0000600002c0ae00
   x28: 0x0000000000000000   fp: 0x000000016d8464b0   lr: 0x000000010577b6a4
    sp: 0x000000016d846480   pc: 0x0000000105115e80 cpsr: 0xa0001000
   far: 0x0000000000000000  esr: 0x56000080  Address size fault

@KaeTar
Copy link

KaeTar commented Feb 19, 2025

After reading through some of the comments above I Searched my codebase for SafeHandle. I found one instance in a low level base class for our implimentation of PropertyChangedBase. It looks like we had dispose methods grabbing a SafeHandle with IntPtr.Zero. looks like it was straight out of the documentation from here:

Implement the dispose pattern

This caused a lot of really bad problems. I wonder how many people have grabbed that out of the documentation and added specifics without removing the SafeHandle(IntPtr.Zero, true) code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Runtime documentation Documentation bug or enhancement, does not impact product or test code
Projects
None yet
Development

No branches or pull requests