nitmir / btdht

A python implementation of the Bittorrent DHT (Distributed Hash Table)
GNU General Public License v3.0
85 stars 30 forks source link

utils.pyx UnboundLocalError: local variable 'data' referenced before assignment #4

Closed emmercm closed 6 years ago

emmercm commented 7 years ago

I'm getting this error frequently with Python 2.7.9 and btdht 0.3.1:

init socket for f289d6ad5d78a5dbbf4605ddafb6bfdbe38aa7ab
Bootstraping
Exception in thread scheduler:io_loop:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 810, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "btdht/utils.pyx", line 1145, in btdht.utils.Scheduler._io_loop (btdht/utils.c:23139)
    dht._process_incoming_message()
  File "btdht/dht.pyx", line 979, in btdht.dht.DHT_BASE._process_incoming_message (btdht/dht.c:21040)
    self.debug(0, "send:%r : (%r, %r)" % (e, data, addr))
UnboundLocalError: local variable 'data' referenced before assignment

Using the example from the readme:

import binascii
import btdht
import time
dht = btdht.DHT()
dht.start()
time.sleep(30)
print(dht.get_peers(binascii.a2b_hex("0403fb4728bd788fbcb67e87d6feb241ef38c75a")))
nitmir commented 7 years ago

The UnboundLocalError is masquerading an socket.error exception. I've fix the masquerading (in the dev branch), so you should get the actual error. Function of why you get an error, we may need to change the socket errors handling. Normally, the only two error that are not cached are Resource temporarily unavailable (which should not happend then reading) and premission denied that tends to be a permanent error. Maybe the full (real) traceback could help.

nitmir commented 6 years ago

Sorry it took so long to publish the fixed version (from the dev branch), I have been very busy lately.