I have simple console TCP server app, and I am trying to make it async. For some reason I am getting deadlock. I run `Test-NetConnection localhost -Port 12345` from PowerShell to trigger incoming connection.

I have an assumption: `OnAcceptCompleted` method is getting called inside `Thread` spawned by OS, and it is not part of `ThreadPool`. But I don't know how to fix it.

```
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;

class Program
{
    private static CancellationTokenSource _shutdownSource = new CancellationTokenSource();

    static async Task Main()
    {
        using var listener = new Socket(SocketType.Stream, ProtocolType.Tcp);
        listener.Bind(new IPEndPoint(IPAddress.Any, 12345));
        listener.Listen(10);

        while (!_shutdownSource.IsCancellationRequested)
        {
            var socket = await AcceptClient(listener, _shutdownSource.Token).ConfigureAwait(false);
            // execution never go this line
            Console.WriteLine($"Client accepted {socket.RemoteEndPoint}");
        }
    }

    private static async Task<Socket> AcceptClient(Socket listener, CancellationToken token)
    {
        var source = new TaskCompletionSource<Socket>();
        var args = new SocketAsyncEventArgs();
        args.UserToken = new TaskCompletionSource<Socket>();
        args.Completed += OnAcceptCompleted;
        if (!listener.AcceptAsync(args))
        {
            OnAcceptCompleted(listener, args);
        }

        using (token.Register(() => source.TrySetCanceled()))
        {
            // we don't need ConfigureAwait(false) here, but just to be sure
            return await source.Task.ConfigureAwait(false);
        }
    }

    private static void OnAcceptCompleted(object sender, SocketAsyncEventArgs args)
    {
        var source = (TaskCompletionSource<Socket>)args.UserToken;
        if (args.SocketError == SocketError.Success)
        {
            // checked in debugger, TaskCompletionSource goes to RanToCompletion status here
            source.TrySetResult(args.AcceptSocket);
        }
        else if (args.SocketError == SocketError.OperationAborted)
        {
            source.TrySetCanceled();
        }
        else
        {
            source.TrySetException(new InvalidOperationException("Socket error = " + args.SocketError));
        }
    }
}

```