We have implemented tls using openssl. While downloading larger data from server getting SSL_ERROR_SYSCALL
error after receiving the some data. For smaller files I am not getting this error, able to download without any error. ERR_get_error() is showing zero for larger files.
We are using linux and c++ framework. How to find reason for the failure? What could be the reason for failure? kindly provide your suggestions.
If you look into the source code for
SSL_get_error()
you'll see, that it returnsSSL_ERROR_SYSCALL
whenever it not sure what exactly happened. It's basically default return code for "unknown" case.For example, in my case (doing non-blocking IO with BIO):
When
n
is 0,err
will beSSL_ERROR_SYSCALL
just because. Howeverst
still will be 0 indicating that there was no real error.SSL_read
just returned 0 because 0 bytes was written to thebuf
.However, look for
errno
/WSAGetLastError()
values after the call for more details.I found the issue to be my companies firewall blocking the requests. Go home and it should work
Check if you call SSL_read() with a buffer size of 0. I have made the following mistake using SSL_pending():
If
nBuf == bufSize
SSL_read() will be called with a buffer size of 0 what leads to SSL_ERROR_SYSCALL with errno == 0.Changing the doReadFd check will avoid this problem:
SSL_ERROR_SYSCALL indicates that some problem happened with the underlying I/O (Should be TCP in this case). So, you can try checking with errno.
OpenSSL help says:
The problem is caused by the network connection being cut and the server re-setting.
Just make sure the connection is Ok before downloading the data.
A similar problem can be seen here when using vagrant.
https://github.com/hashicorp/vagrant/issues/9612