eudemonia-research / spore

Spore is a simple peer-to-peer library for Python.
6 stars 5 forks source link

Exceptions in Spore should not cause parent thread to crash #3

Closed XertroV closed 10 years ago

XertroV commented 10 years ago

When the spore.broadcast() method has an exception it crashes the parent thread - not good.

Suggest spore.broadcast() forks off into it's own thread, or returns True/False based on success or not, but catches any exceptions.

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/local/lib/python3.2/dist-packages/spore/__init__.py", line 61, in send
    self.socket.sendall(rlp.encode([method.encode('utf-8'), payload]))
socket.error: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.2/threading.py", line 693, in run
    self._target(*self._args, **self._kwargs)
  File "/home/xertrov/src/gracht/seeknbuild.py", line 173, in chainBuilder
    self.gracht.broadcast('blocks', ALL_BYTES([[block[0].leaves(), block[1].rawlist, []]]))
  File "/usr/local/lib/python3.2/dist-packages/spore/__init__.py", line 327, in broadcast
    peer.send(method, payload)
  File "/usr/local/lib/python3.2/dist-packages/spore/__init__.py", line 62, in send
    except (BrokenPipeError, OSError):
NameError: global name 'BrokenPipeError' is not defined
devnix commented 10 years ago

Is there a kind of bugfix implemented? I've noticed that if you bind a port number already in use, anything warns you (the chat program keeps with all the input logic, but you will never receive any external input).

If you do Ctrl + C, you can get a message like this:

^CFuture/Task exception was never retrieved:
Traceback (most recent call last):
  File "/usr/local/lib/python3.3/dist-packages/asyncio/base_events.py", line 554, in create_server
    sock.bind(sa)
OSError: [Errno 98] Address already in use

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.3/dist-packages/asyncio/tasks.py", line 281, in _step
    result = coro.send(value)
  File "/usr/local/lib/python3.3/dist-packages/spore/__init__.py", line 200, in _create_server
    self._server = yield from self._loop.create_server(self._protocol_factory, *self._address)
  File "/usr/local/lib/python3.3/dist-packages/asyncio/base_events.py", line 558, in create_server
    % (sa, err.strerror.lower()))
OSError: [Errno 98] error while attempting to bind on address ('127.0.0.1', 5000): address already in use

Traceback (most recent call last):
  File "./test_encryption.py", line 71, in <module>
    message = input(nick.rjust(10).decode() + ": ").encode()
KeyboardInterrupt

It is, to pass all exceptions, currently a good practice? You don't get even an alert in stdout or stderr, and makes the code harder to debug.

ktofu commented 10 years ago

I've removed the catch-all try: except as per devnix's recommendation. If a user wants to wrap their own code in a catch-all try except, they can.