Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#19343 closed Bug (fixed)

TransactionTestCase + TEST_MIRROR + multi_db = deadlock

Reported by: Aymeric Augustin Owned by: Aymeric Augustin
Component: Testing framework Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This ticket is split from https://code.djangoproject.com/ticket/18984#comment:5

When TEST_MIRROR is used, an empty test case within a TransactionTestCase that declares multi_db = True deadlocks.

With MySQL, the test runner dies after the third Ctrl-C with the trace below.

(django-dev)myk@mYk tests % PYTHONPATH=.. ./runtests.py --settings=test_mysql_local test_runner.MirrorDeadlockTest                       ~/Documents/dev/django/tests
Creating test database for alias 'default'...
Creating test database for alias 'other'...
You're going to deadlock, human. MUHAHA.
.^C^C^CE
======================================================================
ERROR: test_teardown_deadlock (regressiontests.test_runner.tests.MirrorDeadlockTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/myk/Documents/dev/django/django/test/testcases.py", line 478, in __call__
    self._post_teardown()
  File "/Users/myk/Documents/dev/django/django/test/testcases.py", line 492, in _post_teardown
    self._fixture_teardown()
  File "/Users/myk/Documents/dev/django/django/test/testcases.py", line 517, in _fixture_teardown
    skip_validation=True, reset_sequences=False)
  File "/Users/myk/Documents/dev/django/django/core/management/__init__.py", line 160, in call_command
    return klass.execute(*args, **defaults)
  File "/Users/myk/Documents/dev/django/django/core/management/base.py", line 252, in execute
    output = self.handle(*args, **options)
  File "/Users/myk/Documents/dev/django/django/core/management/base.py", line 382, in handle
    return self.handle_noargs(**options)
  File "/Users/myk/Documents/dev/django/django/core/management/commands/flush.py", line 64, in handle_noargs
    transaction.rollback_unless_managed(using=db)
  File "/Users/myk/Documents/dev/django/django/db/transaction.py", line 128, in rollback_unless_managed
    connection.rollback_unless_managed()
  File "/Users/myk/Documents/dev/django/django/db/backends/__init__.py", line 222, in rollback_unless_managed
    self._rollback()
  File "/Users/myk/Documents/dev/django/django/db/backends/mysql/base.py", line 420, in _rollback
    BaseDatabaseWrapper._rollback(self)
  File "/Users/myk/Documents/dev/django/django/db/backends/__init__.py", line 58, in _rollback
    return self.connection.rollback()
OperationalError: (2006, 'MySQL server has gone away')

----------------------------------------------------------------------
Ran 1 test in 3.969s

FAILED (errors=1)
Destroying test database for alias 'default'...
Destroying test database for alias 'other'...

Running the test with PostgreSQL also deadlocks, and refuses to die with Ctrl-C, so I don't have a stack trace.

During the deadlock, ps shows:

postgres: django test_django [local] TRUNCATE TABLE waiting  
postgres: django test_django [local] idle in transaction  

Attachments (1)

19343.diff (3.8 KB ) - added by Aymeric Augustin 12 years ago.

Download all attachments as: .zip

Change History (6)

by Aymeric Augustin, 12 years ago

Attachment: 19343.diff added

comment:1 by Aymeric Augustin, 12 years ago

Has patch: set

For the same reason as #18984, it isn't really possible to add a test for this.

The fix can be verified manually by adding this test, and checking if a deadlock happens during teardown

comment:2 by Aymeric Augustin, 12 years ago

Owner: changed from nobody to Aymeric Augustin

comment:3 by Jeremy Dunck, 12 years ago

I've reviewed this patch. Looks good to me.

comment:4 by Aymeric Augustin <aymeric.augustin@…>, 12 years ago

Resolution: fixed
Status: newclosed

In be64dd35fbb9b2b49fa5774b7e7f777df8351c1a:

Fixed #19343 -- Deadlock with TransactionTestCase + TEST_MIRROR + multi_db.

Thanks Jeremy Dunck for the review.

comment:5 by Aymeric Augustin <aymeric.augustin@…>, 12 years ago

In a708b8fcbe49e857d9f900d6375d56f61e22212a:

[1.5.x] Fixed #19343 -- Deadlock with TransactionTestCase + TEST_MIRROR + multi_db.

Thanks Jeremy Dunck for the review.

Backport of be64dd3 from master.

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