Ensure ssl socket is closed on shutdown