Better close/shutdown logic to avoid dangling client connections