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)

patch (1.7 KB ) - added by Koterpillar 11 years ago.
test and patch

Download all attachments as: .zip

Change History (16)

comment:1 by Koterpillar, 11 years ago

Has patch: set

comment:2 by Claude Paroz, 11 years ago

Component: UncategorizedTesting framework
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:3 by anonymous, 11 years ago

We are using only TestCase and TransactionTestCases in our code. CONN_MAX_AGE is set to 180.

comment:4 by Jake Rothenbuhler, 11 years ago

Owner: changed from nobody to Jake Rothenbuhler
Status: newassigned

comment:5 by Jake Rothenbuhler, 11 years ago

Owner: Jake Rothenbuhler removed
Status: assignednew

comment:6 by Claude Paroz, 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 :-(

by Koterpillar, 11 years ago

Attachment: patch added

test and patch

comment:7 by Koterpillar, 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 Mathieu Agopian, 11 years ago

Patch needs improvement: set

This patch is still not working for me on an up to date master.

On a side note, it might be related to #22420 and #22003.

comment:9 by Koterpillar, 11 years ago

Can you share the results you are getting, along with the environment? I'm always getting a success.

comment:10 by Chris Jerdonek, 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 Chris Jerdonek, 8 years ago

Cc: chris.jerdonek@… added

comment:12 by Chris Jerdonek, 8 years ago

Owner: set to Chris Jerdonek
Status: newassigned

comment:13 by Chris Jerdonek, 8 years ago

I posted a pull request for this here. Also, I confirmed on the CI servers that the test I added fails on six of the build configurations (mysql, postgres, and postgis) without the change.

Last edited 8 years ago by Chris Jerdonek (previous) (diff)

comment:14 by Tim Graham, 8 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:15 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In f6cd669f:

Fixed #22414 -- Ensured that LiveServerTestCase closes connections.

Note: See TracTickets for help on using tickets.
Back to Top