Fixes handling closed connections gracefully for agent disconnects.