use ensure to avoid mutex traps when promises catches errors.