change the order of socket close in deinitialize