Store timeout handles, and cancel them when appropriate.
Simplified state check in connect().