Fix issue when losing connection from socket