handling socket error in retry_if_neccessary method