client: improve shutdown condition