fixes socket closing before establishing connection issue