clean shut down if socket is closed