properly shutdown socket and handle exception