Opened 11 years ago
Closed 8 years ago
#22414 closed Bug (fixed)
Persistent connections not closed by LiveServerTestCase, preventing dropping test databases
Reported by: | Koterpillar | Owned by: | Chris Jerdonek |
---|---|---|---|
Component: | Testing framework | Version: | 1.6 |
Severity: | Normal | Keywords: | |
Cc: | chris.jerdonek@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Whenever a PostgreSQL connection is marked as persistent (CONN_MAX_AGE = None
) and a LiveServerTestCase
is executed, the connection from the server thread is never closed, leading to inability to drop the test database.
Attachments (1)
Change History (16)
comment:1 by , 11 years ago
Has patch: | set |
---|
comment:2 by , 11 years ago
Component: | Uncategorized → Testing framework |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:3 by , 11 years ago
comment:4 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 11 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:6 by , 11 years ago
Patch needs improvement: | set |
---|
The test is currently failing for me, as wrapped_close
seems to be called after the test assertion.
I also wonder if closing the connections should happen in LiveServerTestCase._tearDownClassInternal
, but then it will be even more difficult to test :-(
comment:7 by , 11 years ago
Patch needs improvement: | unset |
---|
It turns out the patch was not closing _all_ connections properly - just whatever happened to be in conn
. Fixed.
comment:8 by , 11 years ago
Patch needs improvement: | set |
---|
comment:9 by , 10 years ago
Can you share the results you are getting, along with the environment? I'm always getting a success.
comment:10 by , 8 years ago
I also ran into this issue with Django 1.9.7.
What I observed is that with CONN_MAX_AGE=None
, after LiveServerTestCase.tearDownClass()
, querying PostgreSQL's pg_stat_activity
shows a lingering connection in state "idle" (which was a connection created by the test case).
It looks like the culprit may be Django's LiveServerThread. The idle connections are not closed when the thread terminates. It looks like that's what the most recent patch proposes.
Other info:
PostgreSQL 9.3.13, psycopg2 2.6.2, Python 3.5.2.
comment:11 by , 8 years ago
Cc: | added |
---|
comment:12 by , 8 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:13 by , 8 years ago
I posted a pull request for this here. Also, I confirmed on the CI servers (on six of the build configurations) that the test I added fails without the change.
comment:14 by , 8 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
We are using only
TestCase
andTransactionTestCase
s in our code. CONN_MAX_AGE is set to 180.