Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TLS: SSL_peek is not a const operation
Calling SSL_peek can cause bytes to be read from the raw socket which in turn can upset the select machinery that determines whether there's data available on the socket. Since Curl_ossl_check_cxn only tries to determine whether the socket is alive and doesn't actually need to see the bytes SSL_peek seems like the wrong function to call. We're able to occasionally reproduce a connect timeout due to this bug. What happens is that Curl doesn't know to call SSL_connect again after the peek happens since data is buffered in the SSL buffer and thus select won't fire for this socket. Closes #795
- Loading branch information
856baf5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if recv returns -1 the connection status should be unknown shouldn't it?
856baf5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well. The most common reason for recv to return -1 would probably be EWOULDBLOCK in which case the socket definitely is open. One could maybe make a case that any errno value for should indicate unknown or even closed.
856baf5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No you're right, exclude einprogress ewouldblock eagain. how about
856baf5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do that, it seems more complete and should remove any doubts or possible side-effects that will trigger once in a million and only late Friday evenings. =)
856baf5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Note also that roughly the same code exists in:
curl_socket_t Curl_getconnectinfo(struct SessionHandle _data, struct connectdata *_connp)
which, as far as I can tell is more or less the only caller of Curl_ssl_check_cxn.
There doesn't really seem to be a need to special-case this for ssl anymore IMHO.
856baf5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's the only caller at the moment. How it's handled varies from one SSL backend to another. Most don't support the function and just return -1. DarwinSSL it is implemented though. Changes landed in 2968c83 because Friday comes once a week...