Description
Description
We're encountering this exception periodically on OSX via two paths.
Most of the time we see this call stack:
System.ArgumentException: The supplied System.Net.SocketAddress is an invalid size for the System.Net.IPEndPoint end point. (Parameter 'socketAddress')
?, in EndPoint IPEndPoint.Create(SocketAddress)
?, in SocketError SocketAsyncEventArgs.FinishOperationAccept(SocketAddress)
?, in void SocketAsyncEventArgs.FinishOperationSyncSuccess(int, SocketFlags)
?, in void SocketAsyncEventArgs.FinishOperationAsyncSuccess(int, SocketFlags)
?, in void SocketAsyncEventArgs.CompletionCallback(int, SocketFlags, SocketError)
?, in void SocketAsyncEventArgs.AcceptCompletionCallback(IntPtr acceptedFileDescriptor, Memory<byte> socketAddress, SocketError socketError)
?, in void AcceptOperation.InvokeCallback(bool)
?, in void OperationQueue<TOperation>.ProcessAsyncOperation(TOperation)
?, in void SocketAsyncContext.ProcessAsyncReadOperation(ReadOperation)
?, in void ReadOperation.System.Threading.IThreadPoolWorkItem.Execute()
?, in void AsyncOperation.Process()
?, in void SocketAsyncContext.HandleEvents(SocketEvents)
?, in void SocketAsyncEngine.System.Threading.IThreadPoolWorkItem.Execute()
?, in bool ThreadPoolWorkQueue.Dispatch()
?, in void WorkerThread.WorkerThreadStart()
?, in void Thread.StartCallback()
Once we also saw this call stack:
System.ArgumentException: The supplied System.Net.SocketAddress is an invalid size for the System.Net.IPEndPoint end point. (Parameter 'socketAddress')
?, in EndPoint IPEndPoint.Create(SocketAddress)
?, in SocketError SocketAsyncEventArgs.FinishOperationAccept(SocketAddress)
?, in void SocketAsyncEventArgs.FinishOperationSyncSuccess(int, SocketFlags)
?, in void SocketAsyncEventArgs.FinishOperationSync(SocketError, int, SocketFlags)
?, in SocketError SocketAsyncEventArgs.DoOperationAccept(Socket, SafeSocketHandle, SafeSocketHandle, CancellationToken)
?, in bool Socket.AcceptAsync(SocketAsyncEventArgs, CancellationToken)
?, in ValueTask<Socket> AwaitableSocketAsyncEventArgs.AcceptAsync(Socket, CancellationToken)
?, in ValueTask<Socket> Socket.AcceptAsync(Socket, CancellationToken) x 2
... Calls from our application
Our application implements its own approach to peer-to-peer communication. This is regularly occurring in our testing environment, where we host multiple instances of our application on the same machine, communicating with each other via different ports.
Reproduction Steps
We unfortunately haven't been able to pinpoint a regularly behavior that causes this to happen.
We appear to have only started seeing this issue once we started hosting multiple instances of our application on the same machine.
Expected behavior
While we can safely handle this exception when we're directly invoking it, the majority of the time looks to be via background processing, which we cannot. We are only aware that this exception is occurring because we have logging attached to the unhandled exception handler.
Actual behavior
This error does not occur, or it is always bubbled up to the AcceptAsync caller, such that we are able to catch and handle it.
Regression?
Not 100% sure, but don't believe that a .NET upgrade materialized this. If at all, it would certainly have been a minor one, as we've been on .NET 8 since last year.
Known Workarounds
Our application looks to successfully communicate with the peer on subsequent attempts.
Configuration
.NET 8.0.3, osx-x64
Operating System
Kernel Version: 23.1.0
Name: Darwin
Raw Description: Darwin 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct 9 21:28:31 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T8112
Other information
No response