More work on proper socket close handling