socket shutdown moved to try rather than finally