Fixed a bug will lead to dead lock.