Fix self deadlock bugs.