Even after updating _instance_in_resize_state() to account for rebuilds from vm_states.ERROR, I think there is a further race condition. Down towards the end of _do_rebuild_instance() we call:
This sets the task_state to "None", but the new instance host doesn't get updated until a bit later down at the bottom of rebuild_instance(). During that window, the newly-rebuilt instance will not get accounted for in either _update_usage_from_instances() or _update_usage_from_migrations().
Even after updating _instance_ in_resize_ state() to account for rebuilds from vm_states.ERROR, I think there is a further race condition. Down towards the end of _do_rebuild_ instance( ) we call:
This sets the task_state to "None", but the new instance host doesn't get updated until a bit later down at the bottom of rebuild_instance(). During that window, the newly-rebuilt instance will not get accounted for in either _update_ usage_from_ instances( ) or _update_ usage_from_ migrations( ).