I'm analyzing cryptocurrency market data and using public API of certain exchanges. The program makes HTTPS requests every some seconds. Strangely enough it makes exactly 336 requests and on 337 request it always failed with:
/.rbenv/versions/2.4.5/lib/ruby/2.4.0/net/protocol.rb:44:in `connect_nonblock': SSL_connect SYSCALL returned=5 errno=0 state=error: certificate verify failed (OpenSSL::SSL::SSLError)
I've tried various delays between requests (1 second, 5, 10 seconds), various different exchanges (Bittrex, Poloniex, Tradeogre), various versions of Ruby (2.3.8, 2.4.5, 2.5.3) and various Linux distributions (Ubuntu 18.04.2 LTS, Debian 9.8) on various hostings (Google Compute Engine, Amazon EC2). It's always the same - it fails on the iteration #337. On my local machine (Ruby 2.5.3, Linux Mint 18.3) the program works without such problems, it fails only while running on server. Have no idea what the problem is and how to fix. Thanks in advice.