Fix a newly-introduced deadlock in RelationCounterField.

Review Request #9633 — Created Feb. 12, 2018 and submitted — Latest diff uploaded

Information

Djblets
master
6a282e6...

Reviewers

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.