Fix a logic error which did result in deadlock.