Socket taking 40s to close

I think that you can update the UI right after issuing shutdown (which I guess is done in a separate task) and then continue the graceful close sequence.