Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevented EBADF errors caused by closing sockets prematurely. #4

Open
wants to merge 163 commits into
base: master
Choose a base branch
from
Open

Prevented EBADF errors caused by closing sockets prematurely. #4

wants to merge 163 commits into from

Conversation

justingiorgi
Copy link

Zeroconf.close() immediately closed sockets which child threads may
still need to finish their operations. This was causing EBADF (bad file
descriptor) errors in some cases. Zeroconf.close() now blocks until all
known child threads have stopped then closes the sockets safely.

Added a test and incidentally fixed some tests that weren't running.

wmcbrine added 30 commits July 8, 2013 23:21
a step back in some respects (re-inserting tabs that will be undone a
couple patches hence), so that I can apply the patches going forward.
…ewhere, instead of the unreliable gethostbyname(gethostname()) method (but fall back to that).
…allow for the possibility that they won't? (Or, does this even make sense with sendto()?)
jstasiak and others added 28 commits February 15, 2015 18:08
This is in order for the package's installation to work on Python 3.4+,
solves the same issue as
python-zeroconf/python-zeroconf#22.
Prevents following exception:
```
  File "/Users/paulus/dev/python/netdisco/lib/python3.4/site-packages/zeroconf.py", line 412, in __repr__
    return self.to_string(self.text[:7] + "...")
TypeError: can't concat bytes to str
```
The test helps making sure the situation fixed by
e8299c0 doesn't happen again.
added catch of OSError
added catch of socket.error for python2
IP_MULTICAST_TTL and IP_MULTICAST_LOOP socket options on OpenBSD don't
accept int, only unsigned char. Otherwise you will get an error:
[Errno 22] Invalid argument.
netifaces installation on Python 3.x is broken and there doesn't seem to
be any plan to release a working version on PyPI, instead of using its
fork I decided to use another package providing the required
information.

This closes python-zeroconf/python-zeroconf#31

[1] https://bitbucket.org/al45tair/netifaces/issues/13/0104-install-is-broken-on-python-3x
psutil doesn't seem to work on pypy3:

    Traceback (most recent call last):
      File "/home/travis/virtualenv/pypy3-2.4.0/site-packages/nose/failure.py", line 39, in runTest
        raise self.exc_val.with_traceback(self.tb)
      File "/home/travis/virtualenv/pypy3-2.4.0/site-packages/nose/loader.py", line 414, in loadTestsFromName
        addr.filename, addr.module)
      File "/home/travis/virtualenv/pypy3-2.4.0/site-packages/nose/importer.py", line 47, in importFromPath
        return self.importFromDir(dir_path, fqname)
      File "/home/travis/virtualenv/pypy3-2.4.0/site-packages/nose/importer.py", line 94, in importFromDir
        mod = load_module(part_fqname, fh, filename, desc)
      File "/home/travis/build/jstasiak/python-zeroconf/test_zeroconf.py", line 17, in <module>
        import zeroconf as r
      File "/home/travis/build/jstasiak/python-zeroconf/zeroconf.py", line 35, in <module>
        import psutil
      File "/home/travis/virtualenv/pypy3-2.4.0/site-packages/psutil/__init__.py", line 62, in <module>
        from . import _pslinux as _psplatform
      File "/home/travis/virtualenv/pypy3-2.4.0/site-packages/psutil/_pslinux.py", line 23, in <module>
        from . import _psutil_linux as cext
    ImportError: unable to load extension module
        '/home/travis/virtualenv/pypy3-2.4.0/site-packages/psutil/_psutil_linux.pypy3-24.so':
        /home/travis/virtualenv/pypy3-2.4.0/site-packages/psutil/_psutil_linux.pypy3-24.so: undefined symbol: PyModule_GetState

Additionally netifaces turns out to be possible to install on Python 3,
therefore making it necessary to investigate the original issue.

This reverts commit dd907f2.
Zeroconf.close() immediately closed sockets which child threads may
still need to finish their operations. This was causing EBADF (bad file
descriptor) errors in some cases. Zeroconf.close() now blocks until all
known child threads have stopped then closes the sockets safely. If a
child thread was created that Zeroconf is not aware of (ie a
ServiceBrowser object manually created but not registered in
zeroconf.browsers) the EBADF errors may still occur.

Also some of the unit tests were not in a unittest.TestCase subclass so
they were not running. Added test cases to Misc TestCase and added
default execution of unittest.main().
@justingiorgi
Copy link
Author

Wrong fork. Please do not merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants