Code

Opened 17 months ago

Closed 17 months ago

Last modified 17 months ago

#19343 closed Bug (fixed)

TransactionTestCase + TEST_MIRROR + multi_db = deadlock

Reported by: aaugustin Owned by: aaugustin
Component: Testing framework Version: master
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 aaugustin 17 months ago.

Download all attachments as: .zip

Change History (6)

Changed 17 months ago by aaugustin

comment:1 Changed 17 months ago by aaugustin

  • 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 Changed 17 months ago by aaugustin

  • Owner changed from nobody to aaugustin

comment:3 Changed 17 months ago by jdunck

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

comment:4 Changed 17 months ago by Aymeric Augustin <aymeric.augustin@…>

  • Resolution set to fixed
  • Status changed from new to closed

In be64dd35fbb9b2b49fa5774b7e7f777df8351c1a:

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

Thanks Jeremy Dunck for the review.

comment:5 Changed 17 months ago by Aymeric Augustin <aymeric.augustin@…>

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.