Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not respecting Django's CONN_MAX_AGE database setting #386

Closed
singhravi1 opened this issue Jul 5, 2019 · 6 comments
Closed

Not respecting Django's CONN_MAX_AGE database setting #386

singhravi1 opened this issue Jul 5, 2019 · 6 comments

Comments

@singhravi1
Copy link

Hi,
I'm using uvicorn with gunicorn.
I have assigned CONN_MAX_AGE setting a value say 300 but its closing the connection instantly after completing the request.

My gunicorn configuration is like,

bind = '0.0.0.0:8000'
workers = 3
secure_scheme_headers = {'X-FORWARDED-PROTO': 'https'}
reload = True
errorlog = '-'
loglevel = 'debug'
worker_class = 'uvicorn.workers.UvicornWorker'

And i'm running the following command to start the server,

gunicorn -c gunicorn.conf.py myproject.asgi:application

@tomchristie
Copy link
Member

CONN_MAX_AGE is a setting that determines the maximum age of the database connection.

Doesn’t appear related to Uvicorn.

@singhravi1
Copy link
Author

@tomchristie But the connection is persistent when used with wsgi and without uvicorn worker class.

Any reason you can think of?

@tomchristie
Copy link
Member

Maybe start by trying other ASGI servers: daphne, hypercorn.

If you can isolate this issue to specifically uvicorn, then we should dig further.

@singhravi1
Copy link
Author

Hey @tomchristie, thanks for your suggestion.

I tried all the ASGI servers, i.e. uvicorn, daphne, hypercorn
Every one of them was disconnecting database connection after the request completion.

But when i try running gunicorn with wsgi application, it does not disconnects the database server just after the request completion (respects the CONN_MAX_AGE).

What is the reason behind ASGI servers not respecting this django setting?

Would you recommend running chat server separate from the web server (that would also be a workaround for this)?

@tomchristie
Copy link
Member

Not sure, but this needs raising on channels or django or something - its not a uvicorn issue.

@patrik7
Copy link

patrik7 commented Apr 22, 2020

I do not think this is a uvicorn issue.

I this this provides some more light: benoitc/gunicorn#996 although I was not able to solve the problem yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants