A couple of fixes to prevent deadlocks where we were calling out to the framework whilst holding a lock. This seems to fix some issues in FELIX-3337 (which was failing on trunk, even though it had been resolved before) and hopefully prevents some deadlocks for which we currently have no tests.