YoRyan / nuxhash

A NiceHash cryptocurrency mining client for Linux.
GNU General Public License v3.0
264 stars 164 forks source link

crash when nicehash api not available #21

Closed mysticaltech closed 5 years ago

mysticaltech commented 5 years ago

Hey Ryan, with the latest version from master, it still crashes but this time when the nicehash api is not available. If you could implement a retry with an exponential backoff, it would become more robust, and keep on mining when the api comes back online. Most online services have downtimes, it's normal. I really do not code python, otherwise I would have tried implementing it myself. Thanks!

2018-12-03 13:33:45,548 DEBUG: [13:33:45][0x00007fef010ff700][info] net | x16r | New job '00000136a1ec6ee6', diff=0.03125
2018-12-03 13:33:46,537 WARNING: NiceHash stats: HTTP Error 404: Not Found
2018-12-03 13:33:47,928 DEBUG: [13:33:47][0x00007fef056e6780][info] net | x16r | Share #86 accepted
2018-12-03 13:34:00,552 DEBUG: [13:34:00][0x00007fef010ff700][info] net | x16r | Share #87 accepted
2018-12-03 13:34:05,981 DEBUG: [13:34:05][0x00007fef056e6780][info] net | x16r | Share #88 accepted
2018-12-03 13:34:10,027 DEBUG: [13:34:10][0x00007fef010ff700][info] net | x16r | Share #89 accepted
2018-12-03 13:34:24,539 DEBUG: [13:34:24][0x00007fef056e6780][info] net | x16r | Share #90 accepted
2018-12-03 13:34:32,217 DEBUG: [13:34:32][0x00007fef010ff700][info] net | x16r | Share #91 accepted
2018-12-03 13:34:43,319 DEBUG: [13:34:43][0x00007fef056e6780][info] net | x16r | Share #92 accepted
2018-12-03 13:34:45,692 DEBUG: [13:34:45][0x00007fef010ff700][info] net | x16r | Share #93 accepted
Traceback (most recent call last):
  File "/usr/bin/nuxhashd", line 11, in <module>
    load_entry_point('nuxhash==1.0.0b2', 'console_scripts', 'nuxhashd')()
  File "/usr/lib/python3.6/site-packages/nuxhash/__init__.py", line 3, in nuxhashd
    main()
  File "/usr/lib/python3.6/site-packages/nuxhash/daemon.py", line 108, in main
    session.run()
  File "/usr/lib/python3.6/site-packages/nuxhash/daemon.py", line 266, in run
    self._scheduler.run()
  File "/usr/lib64/python3.6/sched.py", line 154, in run
    action(*argument, **kwargs)
  File "/usr/lib/python3.6/site-packages/nuxhash/daemon.py", line 275, in _switch_algos
    ret_payrates, stratums = nicehash.simplemultialgo_info(self._settings)
  File "/usr/lib/python3.6/site-packages/nuxhash/nicehash.py", line 45, in simplemultialgo_info
    response = api_call('simplemultialgo.info', [])
  File "/usr/lib/python3.6/site-packages/nuxhash/nicehash.py", line 33, in api_call
    raise NicehashAPIError(result)
nuxhash.nicehash.NicehashAPIError: {'error': 'Not ready yet.'}
2018-12-03 13:34:46,801 CRITICAL: Crash! Killing all miners.
Killed
mysticaltech commented 5 years ago

And this problem too, before the error was a 404, and now a 503, in both cases it crashed. It needs to be more robust man! Please.

2018-12-07 12:23:19,363 DEBUG: [12:23:19][0x00007fbe99d9e780][info] net | x16r | Share #770 accepted
2018-12-07 12:23:26,665 WARNING: NiceHash stats: HTTP Error 503: Service Unavailable
2018-12-07 12:23:26,714 DEBUG: [12:23:26][0x00007fbe957b7700][info] net | x16r | Share #771 accepted
2018-12-07 12:23:26,918 DEBUG: [12:23:26][0x00007fbe99d9e780][info] net | x16r | Share #772 accepted
2018-12-07 12:23:33,959 DEBUG: [12:23:33][0x00007fbe957b7700][info] net | x16r | New job '00000136b2a6cfbf', diff=0.0625
2018-12-07 12:23:38,210 DEBUG: [12:23:38][0x00007fbe99d9e780][info] net | x16r | Share #773 accepted
2018-12-07 12:23:45,701 DEBUG: [12:23:45][0x00007fbe957b7700][info] net | x16r | Share #774 accepted
2018-12-07 12:24:01,329 DEBUG: [12:24:01][0x00007fbe99d9e780][info] net | x16r | Share #775 accepted
2018-12-07 12:24:05,110 DEBUG: [12:24:05][0x00007fbe957b7700][info] net | x16r | Share #776 accepted
2018-12-07 12:24:06,723 DEBUG: [12:24:06][0x00007fbe99d9e780][info] net | x16r | Share #777 accepted
2018-12-07 12:24:17,171 DEBUG: [12:24:17][0x00007fbe957b7700][info] net | x16r | Share #778 accepted
2018-12-07 12:24:19,970 DEBUG: [12:24:19][0x00007fbe99d9e780][info] net | x16r | New job '00000136b2a7180c', diff=0.0625
Traceback (most recent call last):
  File "/usr/bin/nuxhashd", line 11, in <module>
    load_entry_point('nuxhash==1.0.0b2', 'console_scripts', 'nuxhashd')()
  File "/usr/lib/python3.6/site-packages/nuxhash/__init__.py", line 3, in nuxhashd
    main()
  File "/usr/lib/python3.6/site-packages/nuxhash/daemon.py", line 108, in main
    session.run()
  File "/usr/lib/python3.6/site-packages/nuxhash/daemon.py", line 266, in run
    self._scheduler.run()
  File "/usr/lib64/python3.6/sched.py", line 154, in run
    action(*argument, **kwargs)
  File "/usr/lib/python3.6/site-packages/nuxhash/daemon.py", line 275, in _switch_algos
    ret_payrates, stratums = nicehash.simplemultialgo_info(self._settings)
  File "/usr/lib/python3.6/site-packages/nuxhash/nicehash.py", line 45, in simplemultialgo_info
    response = api_call('simplemultialgo.info', [])
  File "/usr/lib/python3.6/site-packages/nuxhash/nicehash.py", line 33, in api_call
    raise NicehashAPIError(result)
nuxhash.nicehash.NicehashAPIError: {'error': 'Not ready yet.'}
2018-12-07 12:24:26,960 CRITICAL: Crash! Killing all miners.
Killed
mysticaltech commented 5 years ago

Here's a great article about retrying in Python https://julien.danjou.info/python-retrying/

YoRyan commented 5 years ago

Hey, sorry for the delay. This fix should cover the last few cases I missed.

To clarify, the code is designed to retry on network or API failure. The daemon polls NiceHash every 60 (exact number is configurable) seconds, and if there's an error condition, it maintains the current algorithm selections and leaves excavator to its own devices. Then it polls NiceHash again after the next 60-second interval.

The reason we keep getting these crashes is because I'm forgetting about some of the more obscure Python error classes - including, apparently, the ones I made myself.

Do let me know if this happens again!

mysticaltech commented 5 years ago

Awesome man! Thanks and keep up the good work. Will keep you posted if I see any other errors popping out.