Repository: dotnet/runtime
File: src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs (C#)

Code before:
            }
            catch
            {
                GetAddrInfoExContext.FreeContext(context);
                throw;
            }

            var hints = new Interop.Winsock.AddressInfoEx { ai_family = family };
            if (!justAddresses)
            {
                hints.ai_flags = AddressInfoHints.AI_CANONNAME;
            }

            SocketError errorCode = (SocketError)Interop.Winsock.GetAddrInfoExW(
                hostName, null, Interop.Winsock.NS_ALL, IntPtr.Zero, &hints, &context->Result, IntPtr.Zero, &context->Overlapped, &GetAddressInfoExCallback, &context->CancelHandle);

            if (errorCode == SocketError.IOPending)
            {
                state.RegisterForCancellation(cancellationToken);
            }
            else if (errorCode == SocketError.TryAgain)
            {
                // WSATRY_AGAIN indicates possible problem with reachability according to docs.
                // However, if servers are really unreachable, we would still get IOPenfing here
                // and final result would be posted via overlapped IO.
                // synchronouse failure here may signal issue when GetAddrInfoExW does not work from
                // impersonificated context.
                return Task.FromException(new InvalidOperationException());
            }
            else
            {
                ProcessResult(errorCode, context);
            }

            return state.Task;
        }

        [UnmanagedCallersOnly]
        private static unsafe void GetAddressInfoExCallback(int error, int bytes, NativeOverlapped* overlapped)
        {
            // Can be casted directly to GetAddrInfoExContext* because the overlapped is its first field
            GetAddrInfoExContext* context = (GetAddrInfoExContext*)overlapped;

            ProcessResult((SocketError)error, context);
        }

        private static unsafe void ProcessResult(SocketError errorCode, GetAddrInfoExContext* context)
        {
            try
            {
                GetAddrInfoExState state = GetAddrInfoExState.FromHandleAndFree(context->QueryStateHandle);

Review comment (bug):
```suggestion
                // synchronous failure here may signal issue when GetAddrInfoExW does not work from
```

Code after:
            }
            catch
            {
                GetAddrInfoExContext.FreeContext(context);
                throw;
            }

            var hints = new Interop.Winsock.AddressInfoEx { ai_family = family };
            if (!justAddresses)
            {
                hints.ai_flags = AddressInfoHints.AI_CANONNAME;
            }

            SocketError errorCode = (SocketError)Interop.Winsock.GetAddrInfoExW(
                hostName, null, Interop.Winsock.NS_ALL, IntPtr.Zero, &hints, &context->Result, IntPtr.Zero, &context->Overlapped, &GetAddressInfoExCallback, &context->CancelHandle);

            if (errorCode == SocketError.IOPending)
            {
                state.RegisterForCancellation(cancellationToken);
            }
            else if (errorCode == SocketError.TryAgain)
            {
                // WSATRY_AGAIN indicates possible problem with reachability according to docs.
                // However, if servers are really unreachable, we would still get IOPending here
                // and final result would be posted via overlapped IO.
                // synchronous failure here may signal issue when GetAddrInfoExW does not work from
                // impersonated context.
                GetAddrInfoExContext.FreeContext(context);
                return null;
            }
            else
            {
                ProcessResult(errorCode, context);
            }

            return state.Task;
        }

        [UnmanagedCallersOnly]
        private static unsafe void GetAddressInfoExCallback(int error, int bytes, NativeOverlapped* overlapped)
        {
            // Can be casted directly to GetAddrInfoExContext* because the overlapped is its first field
            GetAddrInfoExContext* context = (GetAddrInfoExContext*)overlapped;

            ProcessResult((SocketError)error, context);
        }

        private static unsafe void ProcessResult(SocketError errorCode, GetAddrInfoExContext* context)
        {
            try
            {