Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
BChip opened this issue Nov 24, 2020 · 7 comments · Fixed by #47435
Assignees
Milestone

Comments

@BChip
Copy link

BChip commented Nov 24, 2020

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.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Nov 24, 2020
@Dotnet-GitSync-Bot
Copy link
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.

@jkotas
Copy link
Member

jkotas commented Nov 24, 2020

Dup of #29935 ? cc @karelz

@ghost
Copy link

ghost commented Nov 24, 2020

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

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 without any success.

Author: BChip
Assignees: -
Labels:

area-System.Net, untriaged

Milestone: -

@BChip
Copy link
Author

BChip commented Nov 24, 2020

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.

@karelz karelz added this to the 6.0.0 milestone Dec 17, 2020
@karelz
Copy link
Member

karelz commented Dec 17, 2020

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.

@karelz karelz added bug and removed untriaged New issue has not been triaged by the area owner labels Dec 17, 2020
@wfurt
Copy link
Member

wfurt commented Jan 22, 2021

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)

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jan 25, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jan 27, 2021
@wfurt wfurt reopened this Jan 29, 2021
@wfurt wfurt modified the milestones: 6.0.0, 5.0.x Jan 29, 2021
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Feb 2, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Feb 11, 2021
@karelz
Copy link
Member

karelz commented Feb 11, 2021

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

@karelz karelz closed this as completed Feb 11, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Mar 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants