BitBotFactory / MikaLendingBot

Automated lending on Cryptocurrency exchanges Poloniex and Bitfinex
http://poloniexlendingbot.readthedocs.io/en/latest/index.html
MIT License
1.11k stars 344 forks source link

[Bug] SSLError: The read operation timed out #151

Closed jeffward01 closed 7 years ago

jeffward01 commented 7 years ago

I just started using the lending bot. I have it configured to the default settings, nothing special set.

After leaving it on for 2 days, and coming back to the terminal, I see some errors. The errors are below. I have not discovered if the errors have any impact, but I thought they should be reported regardless to minimize damage if there is any.

Error:

elcome to Poloniex Lending Bot Started WebServer, lendingbot status available at http://localhost:8000/lendingbot.html 2016-11-29 11:57:43 Placing 0.02787295 BTC at 0.013498% for 2 days... Loan order placed. 2016-11-29 11:58:46 Placing 0.01858197 BTC at 0.0129% for 2 days... Loan order placed. 2016-11-29 11:58:46 Placing 0.00929099 BTC at 0.014099% for 2 days... Loan order placed. 2016-11-29 12:29:59 Placing 0.00619401 BTC at 0.01297% for 2 days... Loan order placed. 2016-11-29 12:29:59 Placing 0.00309701 BTC at 0.013069% for 2 days... Loan order placed. 2016-11-29 12:36:03 Placing 0.00622612 BTC at 0.0125% for 2 days... Loan order placed. 2016-11-29 12:36:03 Placing 0.01245224 BTC at 0.0131% for 2 days... Loan order placed. 2016-11-29 17:04:08 ERROR: ('The read operation timed out',) Lended: [0.3511 BTC @ 0.0102%] 2016-11-29 17:04:08 Traceback (most recent call last): File "lendingbot.py", line 90, in Lending.cancel_all() File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\modules\Lending.py", line 96, in cancel_all loan_offers = api.return_open_loan_offers() File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\modules\Poloniex.py", line 123, in return_open_loan_offers loan_offers = self.api_query('returnOpenLoanOffers') File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\modules\Poloniex.py", line 78, in api_query ret = urllib2.urlopen(urllib2.Request('https://poloniex.com/tradingApi', post_data, headers)) File "C:\Python27\lib\urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 429, in open response = self._open(req, data) File "C:\Python27\lib\urllib2.py", line 447, in _open '_open', req) File "C:\Python27\lib\urllib2.py", line 407, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 1241, in https_open context=self._context) File "C:\Python27\lib\urllib2.py", line 1201, in do_open r = h.getresponse(buffering=True) File "C:\Python27\lib\httplib.py", line 1136, in getresponse response.begin() File "C:\Python27\lib\httplib.py", line 453, in begin version, status, reason = self._read_status() File "C:\Python27\lib\httplib.py", line 409, in _read_status line = self.fp.readline(_MAXLINE + 1) File "C:\Python27\lib\socket.py", line 480, in readline data = self._sock.recv(self._rbufsize) File "C:\Python27\lib\ssl.py", line 756, in recv return self.read(buflen) File "C:\Python27\lib\ssl.py", line 643, in read v = self._sslobj.read(len) SSLError: ('The read operation timed out',)

2016-11-29 17:09:38 ERROR: ('The read operation timed out',) Lended: [0.3511 BTC @ 0.0102%] 2016-11-29 17:09:38 Traceback (most recent call last): File "lendingbot.py", line 90, in Lending.cancel_all() File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\modules\Lending.py", line 96, in cancel_all loan_offers = api.return_open_loan_offers() File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\modules\Poloniex.py", line 123, in return_open_loan_offers loan_offers = self.api_query('returnOpenLoanOffers') File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\modules\Poloniex.py", line 78, in api_query ret = urllib2.urlopen(urllib2.Request('https://poloniex.com/tradingApi', post_data, headers)) File "C:\Python27\lib\urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 429, in open response = self._open(req, data) File "C:\Python27\lib\urllib2.py", line 447, in _open '_open', req) File "C:\Python27\lib\urllib2.py", line 407, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 1241, in https_open context=self._context) File "C:\Python27\lib\urllib2.py", line 1201, in do_open r = h.getresponse(buffering=True) File "C:\Python27\lib\httplib.py", line 1136, in getresponse response.begin() File "C:\Python27\lib\httplib.py", line 453, in begin version, status, reason = self._read_status() File "C:\Python27\lib\httplib.py", line 409, in _read_status line = self.fp.readline(_MAXLINE + 1) File "C:\Python27\lib\socket.py", line 480, in readline data = self._sock.recv(self._rbufsize) File "C:\Python27\lib\ssl.py", line 756, in recv return self.read(buflen) File "C:\Python27\lib\ssl.py", line 643, in read v = self._sslobj.read(len) SSLError: ('The read operation timed out',)

2016-11-29 17:15:08 ERROR: ('The read operation timed out',) Lended: [0.3511 BTC @ 0.0102%] 2016-11-29 17:15:08 Traceback (most recent call last): File "lendingbot.py", line 90, in Lending.cancel_all() File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\modules\Lending.py", line 96, in cancel_all loan_offers = api.return_open_loan_offers() File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\modules\Poloniex.py", line 123, in return_open_loan_offers loan_offers = self.api_query('returnOpenLoanOffers') File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\modules\Poloniex.py", line 78, in api_query ret = urllib2.urlopen(urllib2.Request('https://poloniex.com/tradingApi', post_data, headers)) File "C:\Python27\lib\urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 429, in open response = self._open(req, data) File "C:\Python27\lib\urllib2.py", line 447, in _open '_open', req) File "C:\Python27\lib\urllib2.py", line 407, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 1241, in https_open context=self._context) File "C:\Python27\lib\urllib2.py", line 1201, in do_open r = h.getresponse(buffering=True) File "C:\Python27\lib\httplib.py", line 1136, in getresponse response.begin() File "C:\Python27\lib\httplib.py", line 453, in begin version, status, reason = self._read_status() File "C:\Python27\lib\httplib.py", line 409, in _read_status line = self.fp.readline(_MAXLINE + 1) File "C:\Python27\lib\socket.py", line 480, in readline data = self._sock.recv(self._rbufsize) File "C:\Python27\lib\ssl.py", line 756, in recv return self.read(buflen) File "C:\Python27\lib\ssl.py", line 643, in read v = self._sslobj.read(len) SSLError: ('The read operation timed out',)

2016-11-29 18:05:27 Placing 0.00151246 BTC at 0.014% for 2 days... Loan order placed. 2016-11-29 18:26:36 Placing 0.00100831 BTC at 0.013399% for 2 days... Loan order placed. Lended: [0.3505 BTC @ 0.0102%] error.txt


Error End.

I also attached the error in a .txt for easier readability.

Evanito commented 7 years ago

"This error can happen sometimes if the server takes a little longer to send a response that we allow time for, or if it takes a little longer for the service's response to make it's way back to the caller (i.e network issues as you suggested)." -jamesls

Found this when researching error. Just looks like a run-of-the-mill network error/latency issue, can be solved by:

rnevet commented 7 years ago

The apps already handles the Exception (A) and retry in a later time... Timeout is set in https://github.com/Mikadily/poloniexlendingbot/blob/master/modules/Poloniex.py#L23 to 30sec which for this kind of calls is way too long anyway.

Taking in consideration that this "just happens" and the bot continues, I would suggest we do nothing.

jeffward01 commented 7 years ago

I do have a PIA (Private Internet Access) VPN up and running when the error occurs, couyld that possibly play a factor?

It seems to be that the error occurs each time the loan expires, and the bot reconciles the completed loan, and then processes a new loan. The error occurs in this process. It happened again this morning, I can paste the error logs if you'd like.

@Evanito @rnevet That is good news. So it appears that this is just a 'timeout' error and has no impact on runtime or behavior since the application handles the error its self and recovers. Is this correct to say?

Evanito commented 7 years ago

@jeffward01 Yes that is correct. Your VPN is likely only causing occasional delays in communicating with the API, it is not critical. @rnevet I understand that we already have this problem practically solved. I would still suggest a try...except clause because that allows us to suppress the error message (so users aren't alarmed) easily and take action if needed.

rnevet commented 7 years ago

@Evanito, there is already a try except clause. You can how ever add a different handling for timeout exception - don't print stacktrace, however this will prevent the possibility to detect specific call issues.

Evanito commented 7 years ago

@rnevet I was thinking more along the lines of https://github.com/Mikadily/poloniexlendingbot/commit/5409981ff01f1220d11ad504fc4397294c0d84ff @jeffward01 Could I get you to run the sslerror-fix2 branch for a while and tell me how it works out? It should remove the ugly traceback and replace it with a less threatening message.

rnevet commented 7 years ago

@Evanito, since you don't know which call failed the safest thing is to abort the cycle which is what we are doing. Also avoid hammering the server.

rnevet commented 7 years ago

Basically timeouts are handled correctly.

Evanito commented 7 years ago

I did not change any logic, just replaced an ugly traceback with a more user friendly message. I agree that otherwise it is handled perfectly.

On Thu, Dec 1, 2016, 15:21 Raanan notifications@github.com wrote:

Basically timeouts are handled correctly.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/Mikadily/poloniexlendingbot/issues/151#issuecomment-264326456, or mute the thread https://github.com/notifications/unsubscribe-auth/AFXDuv61AwspnxcEbmtF-DGJGKjzyy6_ks5rD1Z7gaJpZM4K_18J .

Evanito commented 7 years ago

@jeffward01 Any updates? I just pushed a different solution that should be tested, as it will be the one we use. It is #155

jeffward01 commented 7 years ago

@Evanito I apologize for the delay, I thought my Github would give me updates when there are new messages. I just saw the new replies. I will update to the latest release, and run the fix. Ill give you an update today after work. Thanks again!

PS: In order to see if it 'works' I need to wait until my current trades expire (1 - 2 days). I will update to latest, run the new branch, and wait for 1 -2 days until a trade expires (hopefully sooner). I will comment back when I have updated it to the latest release/branch and am waiting for my current trades to expire.

jeffward01 commented 7 years ago

I just switched to the branch sslerror-fix2 and its currentrly working fine. I will report back in 1-2 days after a loan 'completes' and report if it errors. (Previously the error I pasted above will ONLY appear when a loan completes itself, I have to wait for one of my loans to 'complete' in order to verify its working.) Thanks for the help

jeffward01 commented 7 years ago

@Evanito - I just checked it this morning and I saw another error. The error is pasted below and also in a .txt file

2-08 23:32:20 Placing 1.33253333 ETH at 0.006098% for 2 days... Loan order placed. 2016-12-08 23:32:20 Placing 0.66626667 ETH at 0.006198% for 2 days... Loan order placed. 2016-12-08 23:33:22 Canceling all ETH orders... Loan offer canceled. 2016-12-08 23:33:22 Canceling all ETH orders... Loan offer canceled. 2016-12-08 23:33:23 Placing 1.99880000 ETH at 0.005897% for 2 days... Loan order placed. 2016-12-08 23:34:25 Canceling all ETH orders... Loan offer canceled. 2016-12-08 23:34:26 Placing 0.66626667 ETH at 0.0053% for 2 days... Loan order placed. 2016-12-08 23:34:26 Placing 1.33253333 ETH at 0.0054% for 2 days... Loan order placed. 2016-12-09 00:56:01 Placing 0.00146756 BTC at 0.01289% for 2 days... Loan order placed. 2016-12-09 01:38:26 Placing 0.00187824 BTC at 0.0126% for 2 days... Loan order placed. 2016-12-09 04:36:43 Placing 0.00146529 BTC at 0.0133% for 2 days... Loan order placed. 2016-12-09 04:37:45 Placing 0.00146530 BTC at 0.0128% for 2 days... Loan order placed. 2016-12-09 06:40:11 Error: Lended: [0.5004 BTC @ 0.0125%] [1.9988 ETH @ 0.0054%] Traceback (most recent call last): File "lendingbot.py", line 91, in Lending.lend_all() File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\poloniexlendingbot\modules\Lending.py", line 137, in lend_all usable_currencies += lend_cur(cur, total_lended, lending_balances) File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\poloniexlendingbot\modules\Lending.py", line 166, in lend_cur loans = api.return_loan_orders(active_cur, loanOrdersRequestLimit[active_cur]) File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\poloniexlendingbot\modules\Poloniex.py", line 201, in return_loan_orders return self.api_query('returnLoanOrders', {"currency": currency, "limit": limit}) File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\poloniexlendingbot\modules\Poloniex.py", line 66, in api_query ret = urllib2.urlopen(urllib2.Request(req_url)) File "C:\Python27\lib\urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 429, in open response = self._open(req, data) File "C:\Python27\lib\urllib2.py", line 447, in _open '_open', req) File "C:\Python27\lib\urllib2.py", line 407, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 1241, in https_open context=self._context) File "C:\Python27\lib\urllib2.py", line 1198, in do_open raise URLError(err) URLError:

Unhandled error, please open a Github issue so we can fix it! 2016-12-09 06:50:20 Error: Lended: [0.5004 BTC @ 0.0125%] [1.9988 ETH @ 0.0054%] Traceback (most recent call last): File "lendingbot.py", line 90, in Lending.cancel_all() File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\poloniexlendingbot\modules\Lending.py", line 96, in cancel_all loan_offers = api.return_open_loan_offers() File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\poloniexlendingbot\modules\Poloniex.py", line 129, in return_open_loan_offers loan_offers = self.api_query('returnOpenLoanOffers') File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\poloniexlendingbot\modules\Poloniex.py", line 79, in api_query ret = urllib2.urlopen(urllib2.Request('https://poloniex.com/tradingApi', post_data, headers)) File "C:\Python27\lib\urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 429, in open response = self._open(req, data) File "C:\Python27\lib\urllib2.py", line 447, in _open '_open', req) File "C:\Python27\lib\urllib2.py", line 407, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 1241, in https_open context=self._context) File "C:\Python27\lib\urllib2.py", line 1198, in do_open raise URLError(err) URLError:

Unhandled error, please open a Github issue so we can fix it! 2016-12-09 23:10:04 Placing 0.00125229 BTC at 0.0103% for 2 days... Loan order placed. 2016-12-10 00:46:43 Error: Lended: [0.4998 BTC @ 0.0125%] [1.9988 ETH @ 0.0054%] Traceback (most recent call last): File "lendingbot.py", line 90, in Lending.cancel_all() File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\poloniexlendingbot\modules\Lending.py", line 96, in cancel_all loan_offers = api.return_open_loan_offers() File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\poloniexlendingbot\modules\Poloniex.py", line 129, in return_open_loan_offers loan_offers = self.api_query('returnOpenLoanOffers') File "C:\Dev\learning\poloniexlendingbot\poloniexlendingbot-master\poloniexlendingbot\modules\Poloniex.py", line 79, in api_query ret = urllib2.urlopen(urllib2.Request('https://poloniex.com/tradingApi', post_data, headers)) File "C:\Python27\lib\urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 429, in open response = self._open(req, data) File "C:\Python27\lib\urllib2.py", line 447, in _open '_open', req) File "C:\Python27\lib\urllib2.py", line 407, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 1241, in https_open context=self._context) File "C:\Python27\lib\urllib2.py", line 1198, in do_open raise URLError(err) URLError:

Unhandled error, please open a Github issue so we can fix it! Lended: [0.4998 BTC @ 0.0125%] [1.9988 ETH @ 0.0054%]


*** By the way, my VPN was turned off the entire time PoloError.txt