﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31134	ASGI does not closing DB connections properly.	Wojciech Bartosiak	nobody	"I’m testing Django 3.0.1 async features and ASGI performance and I have noticed that when in the configuration:

{{{#!python
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': example,
        'USER': example,
        'PASSWORD': example,
        'HOST': 'localhost',
        'PORT': 5432,
        'ATOMIC_REQUESTS': True
    }
}
}}}

Or when `ATOMIC_REQUESTS` is set to `False` but in `View` I have something like this:

{{{#!python
from django.http import HttpResponse
import datetime
from django.db import transaction


def current_datetime(request):
    with transaction.atomic():
        now = datetime.datetime.now()
        html = ""<html><body>It is now %s.</body></html>"" % now
    return HttpResponse(html)
}}}

Connections/sessions are not being closed and every new request opens a new connection causing:
`django.db.utils.OperationalError: FATAL:  sorry, too many clients already`

This problem does not exist in WSGI mode and/or with/without django_postgrespool2 (with WSGI) this does not exist.
When a server in ASGI mode attacker can use this vector to cut off service.

ASGI command:
{{{#!bash
uvicorn --workers 5 --interface asgi3 --loop asyncio --lifespan off project.asgi:application
}}}

WSGI command:
{{{#!bash
uvicorn --workers 5 --interface wsgi --lifespan off project.wsgi:application
}}}  "	Bug	closed	Database layer (models, ORM)	3.0	Normal	invalid	asgi database	Andrew Godwin Carlton Gibson	Accepted	0	0	0	0	0	0
