Fixed the bug when socket error, the pairs is not properly ended.