move retry logic into the disconnect handler