Unpredictable MethodAccessException deep in HttpClientHandler



  • JustinTothJustinToth USMember ✭✭

    @Jurij - Thanks for the response! So you're saying that when the app starts up, if multiple http requests are made simultaneously, that's when the issue crops up? It was my understanding that this bug actually happens after many days of the app being open. Can you provide more clarity into that, and also exactly how you fixed it? Are you just ensuring that only one request is executed at a time, and you have some sort of queue that holds any pending ones?

  • JurijJurij USMember

    @JustinToth - If I recall correct, you only have to ensure that first "SendAsync" call blocks any other pending calls.
    One of the simple ways to do this is with wrapping the call and block the pending requests with TaskCompletionSource bound to the first call completion. But don't forget to handle its CancellationToken properly ;)

    Reasoning behind the workaround is poor internal initialization that happens once for static part of HttpClient per application lifecycle. Long story short, two initial simultaneous requests that triggers internal initialization potentially cause a race condition with slight chance of causing our exception.

Sign In or Register to comment.