Close socket on shutdown