Added closes when there were errors or the socket connection closed