close socket gracefuly