Just use two defers, make the socket defer after the socket is opened