Search code examples
djangopostpythonanywhere

Django server doesn't seem to be able to respond while requesting


I am trying to build an open-auth like system where the user can log into one app via another.

During the process, my "authentication" app secretly sends a token to the "client" app. Then the client app calls the authentication app asking for the user's details, to check that they haven't changed. Finally, the authentication app responds with the user details, and the user is redirected to the client app and logged in with the token as a password.

All this seems to work well on my local machine. However, when pushed on my public server, things go wrong.

It looks like the authentication app can't handle being asked for user details while it's still waiting for a reply from the client app that should be confirming that the token has been set.

Basically, the client app waits for the authentication app to reply to its request for details, which it never does. So the client app never replies to the authentication app that the token has been set successfully. So the request can never succeed. This is the rough timeline

AUTH   : Posts token to client, waits for 200 response
CLIENT : Receive token, asks for user details, waits for 200 response
AUTH   : Still waiting for its 200 response, so doesn't answer client request. After a while, ends in a 504 gateway timeout error

Should I change my code so that some calls are made asynchronously ? Or am I identifying the issue wrong ?


Solution

  • If you have only one worker, then the worker is busy handling the outer request and so the inner request will never get a response.