check if socket is already closed before closing