Random very long cross-scoped ajax request with Symfony2

I have two subdomains client.domain.com and server.domain.com Client is just index.html with a simple jQuery ajax POJ request.

$.ajax({
  url: 'http://server.domain.com/upload',
  type: 'POST',
  success: function(response){
    console.log(response);
  }
});

      

The server runs symfony2 and has Access-Control-Allow-Origin headers for '*'.

The OPTIONS pre-check request sent by the client is usually (80% of the time) very fast (100ms) and random very very long (10 to 15 seconds timeline + headers ).

I've tested sending OPTIONS requests with Postman and there is absolutely no problem, always fast, so it seems to come from a jquery ajax request. Also the symfony2 profiler says that nothing works with a slow request, so it doesn't seem to come from the server.

I don't really know how to debug this, any suggestions?

+3


source to share


1 answer


it looks like a session locking problem. basically symfony blocks concurrent requests with a session. try adding this code to your controller action, preferably as soon as possible, but not before you finish editing anything that might update the session (usually associated with the user):

public function uploadAction() {
    // code potentially affecting session

    session_write_close(); // unlock session to allow multiple requests with this session

    // rest of the code
}

      



Additional Information:

0


source







All Articles