3

Background

Our API allows users to upload large files, like PDFs, JPGs and PNGs. Recently we have experienced a ton of requests that times out when the server has been idle for some time. Our clients would experience 2 minutes of wait time and then receive a 500 error message.

We use Azure API Management to provide clients with documentation and access to the APIs.

Client -> API Management -> Web App

However, after looking at insight it is clear that the issue is between API Management and our Web App, which is where we have a SSL certificate set up.

The issue

The issue seems to be that sending a large POST request containing a SSL certificate to "wake" the API makes it deadlock. I've debugged the API using application insight as well, but it seems like the request is not received by any operation at all.

After debugging the issue with a brand new Web API project and Web App, I have narrowed it down to that the timeout only occurs if:

  • The server is configured for HTTPS only and/or Client Certificate Required.
  • I let the server be for 5-10 minutes before sending my first request.
  • My first request contains a large file, like a 2 MB PDF file.

I set up the following resources in order to debug the issue.

Web API

I created a brand new project, ASP.NET Web API, framework 4.6. I only added a simple files controller.

using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace DebugCertificate.API.Controllers
{
    public class FilesController : ApiController
    {

        public HttpResponseMessage Post()
        {
            // Success
            return Request.CreateResponse(HttpStatusCode.OK, "Welcome to the POST files resource!");
        }

        public HttpResponseMessage Get()
        {
            // Success
            return Request.CreateResponse(HttpStatusCode.OK, "Welcome to the GET files resource!");
        }

    }
}

Web App

I set up a brand new Azure Web App and configured it with the following settings.

Configuration - General settings

TLS/SSL settings - Protocol settings

Steps to reproduce the issue with Postman:

  1. Wait 5-10 minutes.
  2. Send a POST request to the /api/files resource containing a large file (2 MB in this case).
  3. The timeout occur after 120 seconds.
  4. As long as you only send large POST request, you can repeat step 2.

Notice that I don't even have to send a client certificate with this request for the issue to occur.

Postman request

The issue will not occur

  • When require client certificate and HTTPS only is off.
  • When you send a GET /api/files request first and within 5-10 minutes send the same POST request described in step 2 above.

Possible leads

After diagnosing the Web App in Azure I found the errors that are generated by these requests. I have Googled this description but have not found any information that would fix my issues.

Diagnose and solve problems - Diagnose and solve problems - HTTP 4xx Errors

I found something that sounded similar, but this article sounds like it is between the client and API Management, which is not where we have the SSL certificate set up. Look for the green TIP box.

How to secure APIs using client certificate authentication in API Management

I also found this article containing a few ways to solve the issue, but "priming" the API with an additional request seems like a bit of a hassle.

HTTPS Client Certificate Request freezes when the Server is handling a large PUT/POST Request

Questions

  1. Why is this happening?
  2. Is there any workaround that does not involve "priming" the API? A simple Web.config setting maybe?

Let me now if more information is required!

HashedPassword
  • 169
  • 1
  • 14
  • That blog is pretty unequivocal on what your options are. Azure won't let you set `clientcertnegotiation=enable` when adding an SSL certificate, so priming the connection is pretty much all you can do. If there was a simple setting, that blog would likely have documented it; likewise, if the cause was simple, the blog would likely have documented it. The only other thing I can suggest is raising a support ticket/feature request with Microsoft to allow you to specify `clientcertnegotiation` when adding a cert in the Azure Portal - but that is unlikely to happen soon, if ever. – Ian Kemp Jan 28 '20 at 11:12

1 Answers1

0

Go to your domain under custom domains, click the on proxy domain name and then tick the negotiate client certificate option.

If you are using consumption tier then enable the requests client certificate option.

https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-mutual-certificates-for-clients

Mo Haidar
  • 3,748
  • 6
  • 37
  • 76
  • I tried this last week but the outcome did not change. The issue occurs when sending the request from API Management to the backend Web App. To my understanding this setting only negotiates client certificates between the client and API Management. Note that I can recreate the issue without involving API Management. – HashedPassword Jan 29 '20 at 07:29