Fix race condition in creating entities.