Gunicorn flask is duplicating request four or five times

问题内容:

I am running an app in Heroku using gunicorn and flask.
Whenever any requests come in from the website to the api, they seem to be duplicated several times (sometimes as much as five times).

The request is creating users and it’s a post to /users endpoint. I have added logs and can see that it logs ‘User {email} is created’ several times, and then it will return an error on one of them when user already exists, but I can see that the same request is running in parallel several times until the fastest one actually creates the user.

I expected that requests to the API would only be sent once, and grabbed by one of the workers, not duplicated. I can’t tell what is going wrong, if this a configuration error and I’m missing something in setting up the application?

I’m using flask-restful for the api and pymongo for the db.
I am running my app like this:

if __name__ == '__main__':
    app.run(debug=False)

and procfile has this: web: gunicorn app:app

问题评论:

    
Check on frontend if the submit/whatever button is triggering multiple times, have you set any onclick handler?
    
Post the code from your flask-restful routes.
    
If you’re using Gunicorn, you’re not using app.run. Please edit to include a Minimal, Complete, and Verifiable example.

原文地址:

https://stackoverflow.com/questions/47756087/gunicorn-flask-is-duplicating-request-four-or-five-times

添加评论