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

Code before:
                {
#pragma warning disable CS0162 // Unreachable code detected -- SupportsGetAddrInfoAsync is a constant on *nix.

                    // If the OS supports it and 'hostName' is not an IP Address, resolve the name asynchronously
                    // instead of calling the synchronous version in the ThreadPool.

                    ValidateHostName(hostName);

                    Task t;
                    if (NameResolutionTelemetry.Log.IsEnabled())
                    {
                        t = justAddresses
                            ? (Task)GetAddrInfoWithTelemetryAsync<IPAddress[]>(hostName, justAddresses, family, cancellationToken)
                            : (Task)GetAddrInfoWithTelemetryAsync<IPHostEntry>(hostName, justAddresses, family, cancellationToken);
                    }
                    else
                    {
                        t = NameResolutionPal.GetAddrInfoAsync(hostName, justAddresses, family, cancellationToken);
                    }


                    if (!t.IsFaulted || !(t.Exception?.InnerException is InvalidOperationException))
                    {
                        return t;
                    }
                    // If we failed with InvalidOperationException fall-throgh and use synchronous lookup on threadpool.
                }

                asyncState = family == AddressFamily.Unspecified ? (object)hostName : new KeyValuePair<string, AddressFamily>(hostName, family);
            }

            if (justAddresses)
            {
                return RunAsync(s => s switch
                {
                    string h => GetHostAddressesCore(h, AddressFamily.Unspecified),
                    KeyValuePair<string, AddressFamily> t => GetHostAddressesCore(t.Key, t.Value),
                    IPAddress a => GetHostAddressesCore(a, AddressFamily.Unspecified),
                    KeyValuePair<IPAddress, AddressFamily> t => GetHostAddressesCore(t.Key, t.Value),
                    _ => null
                }, asyncState);
            }
            else
            {
                return RunAsync(s => s switch
                {
                    string h => GetHostEntryCore(h, AddressFamily.Unspecified),
                    KeyValuePair<string, AddressFamily> t => GetHostEntryCore(t.Key, t.Value),
                    IPAddress a => GetHostEntryCore(a, AddressFamily.Unspecified),
                    KeyValuePair<IPAddress, AddressFamily> t => GetHostEntryCore(t.Key, t.Value),
                    _ => null

Review comment (bug):
```suggestion
                    // If we failed with InvalidOperationException fall-through and use synchronous lookup on threadpool.
```

Code after:
                {
#pragma warning disable CS0162 // Unreachable code detected -- SupportsGetAddrInfoAsync is a constant on *nix.

                    // If the OS supports it and 'hostName' is not an IP Address, resolve the name asynchronously
                    // instead of calling the synchronous version in the ThreadPool.
                    // If it fails, we will fall back to ThreadPool as well.

                    ValidateHostName(hostName);

                    Task? t;
                    if (NameResolutionTelemetry.Log.IsEnabled())
                    {
                        t = justAddresses
                            ? GetAddrInfoWithTelemetryAsync<IPAddress[]>(hostName, justAddresses, family, cancellationToken)
                            : GetAddrInfoWithTelemetryAsync<IPHostEntry>(hostName, justAddresses, family, cancellationToken);

                    }
                    else
                    {
                        t = NameResolutionPal.GetAddrInfoAsync(hostName, justAddresses, family, cancellationToken);
                    }

                    // If async resolution started, return task to user. otherwise fall back to sync API on threadpool.
                    if (t != null)
                    {
                        return t;
                    }
                }

                asyncState = family == AddressFamily.Unspecified ? (object)hostName : new KeyValuePair<string, AddressFamily>(hostName, family);
            }

            if (justAddresses)
            {
                return RunAsync(s => s switch
                {
                    string h => GetHostAddressesCore(h, AddressFamily.Unspecified),
                    KeyValuePair<string, AddressFamily> t => GetHostAddressesCore(t.Key, t.Value),
                    IPAddress a => GetHostAddressesCore(a, AddressFamily.Unspecified),
                    KeyValuePair<IPAddress, AddressFamily> t => GetHostAddressesCore(t.Key, t.Value),
                    _ => null
                }, asyncState);
            }
            else
            {
                return RunAsync(s => s switch
                {
                    string h => GetHostEntryCore(h, AddressFamily.Unspecified),
                    KeyValuePair<string, AddressFamily> t => GetHostEntryCore(t.Key, t.Value),
                    IPAddress a => GetHostEntryCore(a, AddressFamily.Unspecified),
                    KeyValuePair<IPAddress, AddressFamily> t => GetHostEntryCore(t.Key, t.Value),