I have an application with a timeout feature on the connection handshake. Recently, the timeout was exercised and it generated an access violation in SSLEAY32.DLL. First, a bit of background.
The implementation in question uses a non-blocking socket. The actual process of connection occurs in it's own thread. All access is otherwise locked, so nothing else is going on at this time. The purpose of the timeout is to prevent the connection from getting into a bad state and never returning, thus effectively hanging the process. If the timeout is triggered, the timeout option does not specifically interfere with the handshake (i.e. the connection thread is not terminated forcefully). Rather, it simply stops it from continuing and the connection thread is allowed to return. A simplified version of the connection code appears below: // Perform SSL Handshake err = 0; while (err != 1) { err = BIO_do_handshake(client_bio); if (err != 1) { // if we've exceed our timeout, just stop trying. if (timeout) { return; } // if we should retry, do so. else if (BIO_should_retry(client_bio)) { continue; } else { // badness [ error handling ] } } } printf("BIO Handshake complete!\n"); The access violation is not guaranteed to occur. There are situations where it simply ends and the process continues normally (well, as 'normally' as far as it can without having established a connection). Q1) Is there something inherently wrong with discontinuing the handshake once it has begun prior to it completing (apart from not actually establishing a connection of course...)? Q2) Is there a better way to discontinue a connection attempt already in progress if i've decided to give up on it?