gilestrolab / ethoscope

a platform from monitoring animal behaviour in real time from a raspberry pi
http://lab.gilest.ro/ethoscope/
GNU General Public License v3.0
17 stars 25 forks source link

Device_scanner get URLerror when the ethoscopes are power off and the Node list is not updated anymore. #151

Closed pepelisu closed 3 years ago

pepelisu commented 3 years ago

Commit 9e5cd58df54cbe480008fb930b0c696ba2206848, in branch Dev possibly introduces a bug. When ethoscopes are powered off, the device_scanner.py raise an exception and therefore the main list of ethoscope in Node interface is not updated anymore. The exception is created by 72 with URLError, however the origin comes from line 443 in _update_id(), since it tries to reach a previously powered off ethoscope.

Full trace (reversed):

Mar 24 09:10:57 node python[1831129]: ethoscope_node.utils.device_scanner.ScanException: Error[Errno 113] No route to host
Mar 24 09:10:57 node python[1831129]:     raise ScanException("Error" + str(e.reason))
Mar 24 09:10:57 node python[1831129]:   File "/opt/ethoscope-node/node_src/ethoscope_node/utils/device_scanner.py", line 72, in _get_json
Mar 24 09:10:57 node python[1831129]:     return f(*args, **kwargs)
Mar 24 09:10:57 node python[1831129]:   File "/opt/ethoscope-node/node_src/ethoscope_node/utils/device_scanner.py", line 40, in f_retry
Mar 24 09:10:57 node python[1831129]:     resp = self._get_json(self._id_url)
Mar 24 09:10:57 node python[1831129]:   File "/opt/ethoscope-node/node_src/ethoscope_node/utils/device_scanner.py", line 443, in _update_id
Mar 24 09:10:57 node python[1831129]:     self._update_id()
Mar 24 09:10:57 node python[1831129]:   File "/opt/ethoscope-node/node_src/ethoscope_node/utils/device_scanner.py", line 487, in _update_info
Mar 24 09:10:57 node python[1831129]:     self._update_info()
Mar 24 09:10:57 node python[1831129]:   File "/opt/ethoscope-node/node_src/ethoscope_node/utils/device_scanner.py", line 299, in _check_instructions_status
Mar 24 09:10:57 node python[1831129]:     self._check_instructions_status(instruction)
Mar 24 09:10:57 node python[1831129]:   File "/opt/ethoscope-node/node_src/ethoscope_node/utils/device_scanner.py", line 278, in send_instruction
Mar 24 09:10:57 node python[1831129]:     device.send_instruction(instruction, post_data)
Mar 24 09:10:57 node python[1831129]:   File "/opt/ethoscope-node/node_src/scripts/server.py", line 330, in post_device_instructions
Mar 24 09:10:57 node python[1831129]:     return func(*args, **kwargs)
Mar 24 09:10:57 node python[1831129]:   File "/opt/ethoscope-node/node_src/scripts/server.py", line 42, in func_wrapper
Mar 24 09:10:57 node python[1831129]: Traceback (most recent call last):

It seems like there is a circle loop. Ethoscpe checks if the problem of not reaching the ethoscope is the change of id, but check_id routine needs to access the ethoscope to get the new id, it does not reach it and then it crashes the scanner.

_get_json should return "device not found" or something similar if URLError is 113, "No route to host" instead of raise an exception

pepelisu commented 3 years ago

Commit #8428c3e should solve this issue.