简体   繁体   中英

GUnicorn / Flask socket timeout

I have a Flask server that is using Gunicorn & Connexion. I'm getting odd behavior where requests seem to "die" (socket hangup) if they run longer than ~150ms. I cannot seem to find any configuration that is specifying a timeout, so my guess is that it is defaulted to GUnicorns 30 seconds.

Gunicorn is using a custom WSGI application ( same config as here ) build off of a connexion.FlaskApp :

con_app = connexion.FlaskApp(__name__)
app = con_app.app

load_configuration(app.config)

con_app.add_api(
    API_SPEC,
    strict_validation=True,
    validate_responses=True,
    resolver=ApiResolver("my.controllers", BASE_PATH),
    options={"openapi_spec_path": f"{BASE_PATH}/documentation.json"},
    pythonic_params=True
)

CORS(app, resources={f"{BASE_PATH}/documentation.json": {"origins": "*"}})
ApiAuth(app)

I'm not getting any sort of timeout error, my server simply restarts before the request completes and a response is never sent. I've found other who have had similar behavior , but they seem to fix it by swapping to uWSGI.

My service is deployed in Docker and is not launched using the gunicorn command, but rather by running the connexion app with app.run(port=9090) .

Has anyone encountered something similar and have any ideas on how I can fix it? Due to my environment, I do not believe I'm able to swap to uWSGI and rather need this to work with gunicorn.

It turns out my server was being launched with a Python package called reload that reloads upon any file changes. My server wrote to logs and the server was reloaded on this change before requests were completed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM