Fix a newly-introduced deadlock in RelationCounterField.

Review Request #9633 - Created Feb. 12, 2018 and submitted

Christian Hammond

The recent fix for tracking multiple instances in RelationCounterField
introduced a deadlock that manifested during a Review Board test suite
run. It was possible for a weak reference to drop while adding a new
instance, causing _reset_state to grab a locl while _store_state was
running (as part of the instantiation of an InstanceState).

We now delay setting up InstanceState until we leave the lock,
allowing the lock to just center around manipulating the state map, and
allowing setup/destroying to be in its own locks.

My reliably-broken unit test run no longer deadlocks.

All Djblets and Review Board unit tests pass.

David Trowbridge
  1. Ship It!
Christian Hammond
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-1.0.x (743d14c)