Handle connect failure more robustly.