fix infinity loop when socket closed