Skip to content

ASP.NET 5 -- Impersonation -- A call to WSALookupServiceEnd was made while this call was still processing #45165

Closed

Description

@BChip

Description

ASP.NET 5 -- Impersonation -- A call to WSALookupServiceEnd was made while this call was still processing

As a note, this does work locally with IIS Express. This is only happening when the code is deployed running on IIS Windows Server 2012.

Configuration

  • Which version of .NET is the code running on?
    .NET 5
  • What OS and version, and what distro if applicable?
    Windows Server 2012 -- IIS 11
  • What is the architecture (x64, x86, ARM, ARM64)?
    x64

Regression?

Doesn't work in .NET Core 3.1 or in .NET 5

Code

       public async Task<Results<string>> SendRequest(HttpRequestMessage request)
        {
            try
            {
                WindowsIdentity identity = (WindowsIdentity)_httpContextAccessor.HttpContext.User.Identity;
                return await WindowsIdentity.RunImpersonated(identity.AccessToken, async () =>
                {
                    using (var httpResp = await _client.SendAsync(request))
                    {
                        if (httpResp.IsSuccessStatusCode)
                        {
                            return (await httpResp.Content.ReadAsStringAsync()).AsResultValue();
                        }
                        else
                        {
                            var content = await httpResp.Content.ReadAsStringAsync();

                            var result = Utilities.Deserialize<Error>(content.AsResultValue<string>());
                            if (result.IsValue && result.Value.Code != null)
                            {
                                return Results<string>.AsResultError(new ErrorValue((int)result.Value.Code, result.Value.Message));
                            }
                            var phrase = !string.IsNullOrEmpty(httpResp.ReasonPhrase) ? $"httpResp.ReasonPhrase {content}" : $"unable to complete request due to {content}";
                            return Results<string>.AsResultError(new ErrorValue((int)httpResp.StatusCode, phrase));
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                return ex.AsResultError<string>();
            }
        }

Error

2020-11-14 11:23:34.854 -05:00 [ERR] Status Code 500 - an internal error has occurred
2020-11-14 11:23:34.854 -05:00 [ERR] A call to WSALookupServiceEnd was made while this call was still processing. The call has been canceled. (___.___.com:443)
2020-11-14 11:23:34.855 -05:00 [ERR]    at System.Net.Http.ConnectHelper.ConnectAsync(Func`3 callback, DnsEndPoint endPoint, HttpRequestMessage requestMessage, 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.GetHttpConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.AuthenticationHelper.SendWithAuthAsync(HttpRequestMessage request, Uri authUri, Boolean async, ICredentials credentials, Boolean preAuthenticate, Boolean isProxyAuth, Boolean doRequestAuth, HttpConnectionPool pool, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)
   at ApiClient.<>c__DisplayClass3_0.<<SendRequest>b__0>d.MoveNext() in 
--- End of stack trace from previous location ---

As an additional note, I did try setting DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER = 0 (.net core 3.1 and .net 5) without any success.

I have tried running as the system administrator as well and receiving the same error.

Activity

  1. added
    untriaged
    on Nov 24, 2020
  2. Dotnet-GitSync-Bot commented on Nov 24, 2020

    @Dotnet-GitSync-Bot
    Collaborator

    I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

  3. jkotas commented on Nov 24, 2020

    @jkotas
    Member

    Dup of #29935 ? cc @karelz

  4. BChip commented on Nov 24, 2020

    @BChip
    Author

    Dup of #29935 ? cc @karelz

    @jkotas I thought it might be, but I don't see that issue referencing the same error log I am experiencing: A call to WSALookupServiceEnd was made while this call was still processing -- I definitely think they are relatable though.

  5. added this to the 6.0.0 milestone on Dec 17, 2020
  6. karelz commented on Dec 17, 2020

    @karelz
    Member

    Triage: Looks like a regression -- @wfurt can you check if it is a dupe of #29935 or if it is another regression, potentially worth servicing.

  7. added and removed
    untriaged
    on Dec 17, 2020
  8. wfurt commented on Jan 22, 2021

    @wfurt
    Member

    I'm running into this on Windows 8 while working on new test for #29935. So it is probably same underlying issue (or related) but the manifestation is different. (so the fix will likely not work)

  9. ghost added
    in-pr
    on Jan 25, 2021
  10. ghost removed
    in-pr
    on Jan 27, 2021
  11. reopened this on Jan 29, 2021
  12. modified the milestones: 6.0.0, 5.0.x on Jan 29, 2021
  13. ghost added
    in-pr
    on Feb 2, 2021
  14. ghost removed
    in-pr
    on Feb 11, 2021
  15. karelz commented on Feb 11, 2021

    @karelz
    Member

    Fixed in 6.0 (master) in PR #47435 and in 5.0.4 in PR #47657

  16. ghost locked as resolved and limited conversation to collaborators on Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions