We seem to be having the same problem: most api calls work without problems, 1 in 20 fails.
Here are some examples:
CURL call failed: SSL read: error:140943FC:SSL routines:SSL3_READ_BYTES:sslv3 alert bad record mac, errno 0
* About to connect() to api.twitter.com port 443 (#396)
* Trying 199.16.156.231...
* Adding handle: conn: 0x3c69510
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 396 (0x3c69510) send_pipe: 1, recv_pipe: 0
* Connected to api.twitter.com (199.16.156.231) port 443 (#396)
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSL connection using ECDHE-RSA-AES128-SHA256
* Server certificate:
* subject: C=US; ST=California; L=San Francisco; O=Twitter, Inc.; OU=Twitter Security; CN=api.twitter.com
* start date: 2016-06-29 00:00:00 GMT
* expire date: 2019-09-19 12:00:00 GMT
* subjectAltName: api.twitter.com matched
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA
* SSL certificate verify ok.
> GET /1.1/search/tweets.json?count=100&q=fees%20fgb&result_type=recent&since_id=785918597679820800&tweet_mode=extended HTTP/1.1
User-Agent: themattharris' HTTP Client
Host: api.twitter.com
Accept: */*
Accept-Encoding: deflate, gzip
Authorization: OAuth oauth_consumer_key="xxx", oauth_nonce="xxx", oauth_signature="xxx", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1477295348", oauth_token="xxx", oauth_version="1.0"
* SSL read: error:140943FC:SSL routines:SSL3_READ_BYTES:sslv3 alert bad record mac, errno 0
* Closing connection 396
As you can see, we get the “alert bad record mac”. We’re not setting protocol or cipher explicitly, we’re letting OpenSSL handle that.
CURL call failed: Operation timed out after 30001 milliseconds with 0 out of 0 bytes received
* About to connect() to api.twitter.com port 443 (#918)
* Trying 199.16.156.199...
* Adding handle: conn: 0x402c4c0
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 918 (0x402c4c0) send_pipe: 1, recv_pipe: 0
* Connected to api.twitter.com (199.16.156.199) port 443 (#918)
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* Operation timed out after 30001 milliseconds with 0 out of 0 bytes received
* Closing connection 918
In the example above we’re getting a timeout from OpenSSL
CURL call failed: Unknown SSL protocol error in connection to api.twitter.com:443
* About to connect() to api.twitter.com port 443 (#317)
* Trying 199.16.156.199...
* Adding handle: conn: 0x3c31d00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 317 (0x3c31d00) send_pipe: 1, recv_pipe: 0
* Connected to api.twitter.com (199.16.156.199) port 443 (#317)
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* Unknown SSL protocol error in connection to api.twitter.com:443
* Closing connection 317
In the example above, we get an “unknown SSL protocol” …
All of these errors happen seemly at random, at multiple API endpoints, (e.g. the media upload endpoint, but also search tweets endpoint), and we always use the same code for it. If we do tests with always uploading the same image the the media upload endpoint in a simple for loop, we’ll trigger an Curl/OpenSSL error ± 1 time in 20 tries. The other 19 times it just works… Do you guys have any idea?