djangoajaxazureweb-applications

Azure Web App blocking AJAX requests to django application


I have a django (4.2.13 + python 3.10) application that at certain point makes AJAX requests to display progress to user while processing data from uploaded file.

When I try this locally on my computer (linux) it works well and progress bar is updated from data received in response of AJAX calls. Similarly it also works on a test server (linux + nginx + gunicorn) and displays progress without hassle.

On the browser side I use jQuery .post command to make calls.

When I deploy same app to the Azure Web App it doesn't allow any of the calls to go through, all remain in Pending state in the browser and there is absolutely no trace anywhere in the Azure logs.

Any hints?

EDIT:

This is query from my template that checks process through background call and updates progress bar:

await sleep (400);
while (current_row < total_rows) {
  $.post('ppro_bar/get_progress_data', {'test': ''})
     .done(function(data) {
       if (typeof data.data != "undefined") {
         current_row = data.data.current_row;
         total_rows = data.data.total_rows;
         percent_progress = (current_row/total_rows)*100;
      
         progress_bar.innerHTML = `
           <div class="progress-bar progress-bar-striped
           progress-bar-animated" role="progressbar" style="width: 
           ${percent_progress}%" 
           aria-valuenow="${percent_progress}" 
           aria-valuemin="0" aria-valuemax="100"></div>`;
       }
     });
     await sleep(100);
   }
}

I also tried GET instead of POST but no luck. I can see that my browser created requests, but they all remain in Pending state, while on the server side I don't see any incoming requests.

As mentioned before, this works on normal Linux/NGINX/gunicorn setup.

EDIT 2:

What I forgot to mention is that I have other ajax calls that are executed normally. The only difference is that those calls (that works) are executed while browser is idling, so that are the only calls to the server in that session at the moment. The non-working calls are executed in parallel with normal code (uploading data) and it seems that the Azure is blocking this calls while the original call is still in progress. Everything else is identical.

Let me explain how it woks:

  1. Django form is submitted that has file for upload - initiated
  2. AJAX progress bar code (parallel with first call) - blocked
  3. AJAX progress bar code (parallel with first call) - blocked
  4. ... (more AJAX calls - all blocked)
  5. Upload is done, and processed - first call completed
  6. Redirect to uploaded file analysis - completed normally

So it seems that some kind of firewall is blocking parallel calls, don't have any idea why and how to enable that.


Solution

  • OK, so I found a problem and finally resolved it. Azure Web App uses gunicorn to run python / django code and for some reason by default it spawns just one worker. Changed to start multiple workers and now everything works.

    This is code you need to put into Web App configuration under Startup Command:

    gunicorn --bind=0.0.0.0 --timeout 600 --workers=4 my_proj.wsgi:application
    

    Hope this will help others with similar problems.