[Django] #22414: Persistent connections not closed by LiveServerTestCase, preventing dropping test databases

24 views
Skip to first unread message

Django

unread,
Apr 9, 2014, 11:55:31 PM4/9/14
to django-...@googlegroups.com
#22414: Persistent connections not closed by LiveServerTestCase, preventing
dropping test databases
-------------------------------+--------------------
Reporter: Koterpillar | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/22414>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 9, 2014, 11:56:43 PM4/9/14
to django-...@googlegroups.com
#22414: Persistent connections not closed by LiveServerTestCase, preventing
dropping test databases
-------------------------------+--------------------------------------

Reporter: Koterpillar | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Koterpillar):

* needs_better_patch: => 0
* has_patch: 0 => 1
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/22414#comment:1>

Django

unread,
Apr 12, 2014, 8:22:59 AM4/12/14
to django-...@googlegroups.com
#22414: Persistent connections not closed by LiveServerTestCase, preventing
dropping test databases
-----------------------------------+------------------------------------
Reporter: Koterpillar | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by claudep):

* type: Uncategorized => Bug
* component: Uncategorized => Testing framework
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/22414#comment:2>

Django

unread,
Apr 12, 2014, 10:48:02 AM4/12/14
to django-...@googlegroups.com
#22414: Persistent connections not closed by LiveServerTestCase, preventing
dropping test databases
-----------------------------------+------------------------------------
Reporter: Koterpillar | Owner: nobody

Type: Bug | Status: new
Component: Testing framework | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by anonymous):

We are using only `TestCase` and `TransactionTestCase`s in our code.
CONN_MAX_AGE is set to 180.

--
Ticket URL: <https://code.djangoproject.com/ticket/22414#comment:3>

Django

unread,
Apr 14, 2014, 5:03:01 PM4/14/14
to django-...@googlegroups.com
#22414: Persistent connections not closed by LiveServerTestCase, preventing
dropping test databases
-------------------------------------+-------------------------------------
Reporter: Koterpillar | Owner:
Type: Bug | jrothenbuhler
Component: Testing framework | Status: assigned
Severity: Normal | Version: 1.6
Keywords: | Resolution:
Has patch: 1 | Triage Stage: Accepted
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jrothenbuhler):

* owner: nobody => jrothenbuhler
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/22414#comment:4>

Django

unread,
Apr 14, 2014, 5:46:50 PM4/14/14
to django-...@googlegroups.com
#22414: Persistent connections not closed by LiveServerTestCase, preventing
dropping test databases
-----------------------------------+------------------------------------
Reporter: Koterpillar | Owner:

Type: Bug | Status: new
Component: Testing framework | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by jrothenbuhler):

* owner: jrothenbuhler =>
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/22414#comment:5>

Django

unread,
Apr 19, 2014, 12:24:00 PM4/19/14
to django-...@googlegroups.com
#22414: Persistent connections not closed by LiveServerTestCase, preventing
dropping test databases
-----------------------------------+------------------------------------
Reporter: Koterpillar | Owner:
Type: Bug | Status: new
Component: Testing framework | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by claudep):

* needs_better_patch: 0 => 1


Comment:

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 :-(

--
Ticket URL: <https://code.djangoproject.com/ticket/22414#comment:6>

Django

unread,
May 11, 2014, 9:35:21 PM5/11/14
to django-...@googlegroups.com
#22414: Persistent connections not closed by LiveServerTestCase, preventing
dropping test databases
-----------------------------------+------------------------------------
Reporter: Koterpillar | Owner:
Type: Bug | Status: new
Component: Testing framework | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by Koterpillar):

* needs_better_patch: 1 => 0


Comment:

It turns out the patch was not closing _all_ connections properly - just
whatever happened to be in `conn`. Fixed.

--
Ticket URL: <https://code.djangoproject.com/ticket/22414#comment:7>

Django

unread,
May 16, 2014, 12:52:05 PM5/16/14
to django-...@googlegroups.com
#22414: Persistent connections not closed by LiveServerTestCase, preventing
dropping test databases
-----------------------------------+------------------------------------
Reporter: Koterpillar | Owner:
Type: Bug | Status: new
Component: Testing framework | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by magopian):

* needs_better_patch: 0 => 1


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/22414#comment:8>

Django

unread,
Jun 23, 2014, 1:14:13 AM6/23/14
to django-...@googlegroups.com
#22414: Persistent connections not closed by LiveServerTestCase, preventing
dropping test databases
-----------------------------------+------------------------------------
Reporter: Koterpillar | Owner:
Type: Bug | Status: new
Component: Testing framework | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by Koterpillar):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/22414#comment:9>

Django

unread,
Jul 9, 2016, 12:42:38 PM7/9/16
to django-...@googlegroups.com
#22414: Persistent connections not closed by LiveServerTestCase, preventing
dropping test databases
-----------------------------------+------------------------------------
Reporter: Koterpillar | Owner:
Type: Bug | Status: new
Component: Testing framework | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by cjerdonek):

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
[https://github.com/django/django/blob/418658f453bed7fe7949dda26651aab370003e6a/django/test/testcases.py#L1230
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/22414#comment:10>

Django

unread,
Jul 9, 2016, 12:43:12 PM7/9/16
to django-...@googlegroups.com
#22414: Persistent connections not closed by LiveServerTestCase, preventing
dropping test databases
-----------------------------------+------------------------------------
Reporter: Koterpillar | Owner:
Type: Bug | Status: new
Component: Testing framework | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by cjerdonek):

* cc: chris.jerdonek@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/22414#comment:11>

Django

unread,
Aug 15, 2016, 3:39:20 PM8/15/16
to django-...@googlegroups.com
#22414: Persistent connections not closed by LiveServerTestCase, preventing
dropping test databases
-----------------------------------+-------------------------------------
Reporter: Koterpillar | Owner: cjerdonek
Type: Bug | Status: assigned

Component: Testing framework | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------------+-------------------------------------
Changes (by cjerdonek):

* owner: => cjerdonek


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/22414#comment:12>

Django

unread,
Aug 15, 2016, 8:40:07 PM8/15/16
to django-...@googlegroups.com
#22414: Persistent connections not closed by LiveServerTestCase, preventing
dropping test databases
-----------------------------------+-------------------------------------
Reporter: Koterpillar | Owner: cjerdonek
Type: Bug | Status: assigned
Component: Testing framework | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------------+-------------------------------------

Comment (by cjerdonek):

I posted a pull request for this
[https://github.com/django/django/pull/7096 here]. Also, I confirmed on
the CI servers (on six of the build configurations) that the test I added
fails without the change.

--
Ticket URL: <https://code.djangoproject.com/ticket/22414#comment:13>

Django

unread,
Aug 18, 2016, 7:15:52 PM8/18/16
to django-...@googlegroups.com
#22414: Persistent connections not closed by LiveServerTestCase, preventing
dropping test databases
-------------------------------------+-------------------------------------

Reporter: Koterpillar | Owner: cjerdonek
Type: Bug | Status: assigned
Component: Testing framework | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 1 => 0

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/22414#comment:14>

Django

unread,
Aug 19, 2016, 12:47:59 PM8/19/16
to django-...@googlegroups.com
#22414: Persistent connections not closed by LiveServerTestCase, preventing
dropping test databases
-------------------------------------+-------------------------------------
Reporter: Koterpillar | Owner: cjerdonek
Type: Bug | Status: closed

Component: Testing framework | Version: 1.6
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"f6cd669ff203192c29495174e53da6b16883b039" f6cd669f]:
{{{
#!CommitTicketReference repository=""
revision="f6cd669ff203192c29495174e53da6b16883b039"
Fixed #22414 -- Ensured that LiveServerTestCase closes connections.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22414#comment:15>

Reply all
Reply to author
Forward
0 new messages