ethereum / pydevp2p

Python Implementation of the Ethereum P2P stack
MIT License
249 stars 335 forks source link

OS X: Tests fail with "Address already in use" errors #36

Open ulope opened 8 years ago

ulope commented 8 years ago

On OS X various tests fail with "Address already in use" errors. The reason is that some tests try to restart an app on the same port in quick succession or use the same port for different but quickly succeeding tests.

In theory this should be no problem because gevent by default configures sockets to SO_REUSEADDR but apparently there is different behaviour between OS X and Linux in this regard.

Example:

______________________________________________________________ test_disconnect _______________________________________________________________

        app_helper.run(ExampleApp, ExampleServiceAppDisconnect,
>                      num_nodes=3, min_peers=2, max_peers=1)

devp2p/tests/test_full_app.py:215:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
devp2p/app_helper.py:105: in run
    serve_until_stopped(apps)
devp2p/app_helper.py:59: in serve_until_stopped
    app.start()
devp2p/app.py:37: in start
    service.start()
devp2p/discovery.py:569: in start
    self.server.start()
/Users/ulo/.cache/tox/pydevp2p/py27/lib/python2.7/site-packages/gevent/baseserver.py:280: in start
    self.init_socket()
/Users/ulo/.cache/tox/pydevp2p/py27/lib/python2.7/site-packages/gevent/server.py:145: in init_socket
    self.socket = self.get_listener(self.address, self.family)
/Users/ulo/.cache/tox/pydevp2p/py27/lib/python2.7/site-packages/gevent/server.py:155: in get_listener
    return _udp_socket(address, reuse_addr=self.reuse_addr, family=family)
/Users/ulo/.cache/tox/pydevp2p/py27/lib/python2.7/site-packages/gevent/server.py:197: in _udp_socket
    sock.bind(address)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <socket at 0x1078d1f10 fileno=23 sock=0.0.0.0:0>, args = (('0.0.0.0', 29870),)

>   ???
E   error: [Errno 48] Address already in use: ('0.0.0.0', 29870)
ulope commented 8 years ago

This might have been fixed in 3016cda1f34ac7a763b809cf3a5ebaff5c5c4c23. If it doesn't reappear we can close this.