Fixed bugs in connection timeout implementation

Bugs:
1. In `init` stage, if an error occurred before the connection timeout error, the timer was not cleared.
2. When connection timed out, the socket was not closed immediately, still had to wait for an extra time.