Fix potential hang in https handshake