Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9268049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:42:35+00:00 2026-06-18T14:42:35+00:00

We’ve written a DelegatingHandler that handles the authentication scheme for a REST api that

  • 0

We’ve written a DelegatingHandler that handles the authentication scheme for a REST api that we’re calling. However, we seem to get into a situation where the inner WebRequestHandler stops making requests.

I’m looking for any help or advice on anything that can cause this handler to just stop working.

I’ve taken a look and I can’t see any internal state that the WebRequestHandler might have – but tracing through the internals of the attempt to send a message, I can see in StartGettingResponse (from HttpClientHandler):

    {
        if (state.identity != null)
        {
            using (state.identity.Impersonate())
            {
                state.webRequest.BeginGetResponse(this.getResponseCallback, state);
                goto Label_0046;
            }
        }
        state.webRequest.BeginGetResponse(this.getResponseCallback, state);
    Label_0046:
        state.requestMessage.MarkRtcFlushComplete();
    }

identity is null. BeginGetResponse is called, but GetResponseCallback (that getResponseCallback is a cached delegate for) is never called. We see no exception. There’s no network traffic (of any kind).


The code for our delegating handler:

if (request.Headers.Authorization == null)
{
    ClaimsIdentity ident = User == null ? null : User.Identity as ClaimsIdentity;
    if (PreAuthenticate)
    {
        var token = await GenerateAuthenticationToken(ident, guessedRealm,true);
        if (cancellationToken.IsCancellationRequested) return null;
        if (token != null)
        {
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
        }
    }
    var firstFlight = await base.SendAsync(request, cancellationToken);

    if (firstFlight.StatusCode != System.Net.HttpStatusCode.Unauthorized) return firstFlight;

    var wwwAuth = firstFlight.Headers.WwwAuthenticate;

    var bearerAuth = wwwAuth.SingleOrDefault(hv => hv.Scheme == "Bearer");

    var realmInfo = bearerAuth.Parameter;

    var realm = realmInfo.Substring(7).TrimEnd('"');

    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer",
        await GenerateAuthenticationToken(ident, realm,false)
    );
    if (cancellationToken.IsCancellationRequested) return null;
}
return await base.SendAsync(request, cancellationToken);

(Error checks and paths not followed removed – except PreAuthenticate is false). We can get into a situation where the first call to SendAsync returns (as expected) a 401 response. We generate a suitable authorization token and attach it as a header. But then the second call to SendAsync never causes any network traffic to occur.

I’m using MS Network Monitor to check the network traffic, and it can see the first request (and several previous requests that also use this same handler but don’t encounter the same issue).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:42:36+00:00Added an answer on June 18, 2026 at 2:42 pm

    It turns out that we were leaking the HttpResponseMessage objects returned by some previous calls, and not calling Dispose on them. (In fact, even in the code snippet I’ve shown, we leak firstFlight)

    It’s not especially obvious that this leak is occurring, and only one or two of them leaked is enough that subsequent requests are queued internally by System.Net.Connection but never actually sent (I think because it’s enforcing the HTTP Connection limit per server)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.