brooklyncentral/brooklyn — pull request #1184 by aledsage (2014-02-03 12:50:26+00:00)
Title: Rebind: don't persist (i.e. overwrite) state until rebind() is complete

Fixes non-deterministic failures in rebind (I hope!).

Problem was that on rebind(), it was persisting the entity's state immediately - as soon as the entity was instantiated, rather than waiting until it was fully configured. So there was a race where it could persist the currently-empty entity/location object with its null fields, and then when it tried to restore the entity it would fail because the file contained a blank entity/location.

I think this bug was introduced by the two-phase entity instantiation + initialisation, where we read the mementos twice in rebind().

However, it was a bad thing to be doing anyway because we were overwriting good state with the state of entities that might have been about to fail to rebind.