[RFC/MERGE] select.select() raises EBADF on closed socket on Mac OS X

John Arbash Meinel john at arbash-meinel.com
Thu Apr 12 22:38:56 BST 2007


I was testing FTP support on my Mac OSX laptop, and I saw a lot of
tracebacks involving EBADF.

Exception in thread Thread-1:
Traceback (most recent call last):
  File
"/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/threading.py",
line 442, in __bootstrap
    self.run()
  File
"/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/threading.py",
line 422, in run
    self.__target(*self.__args, **self.__kwargs)
  File
"/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/asyncore.py",
line 196, in loop
    poll_fun(timeout, map)
  File
"/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/asyncore.py",
line 122, in poll
    r, w, e = select.select(r, w, e, timeout)
error: (9, 'Bad file descriptor')



It seems that medusa uses asyncore, and asyncore dispatches based on
select.select().

Our code is doing:


class FtpServer(TransportServer):
...

    def tearDown(self):
        """See bzrlib.transport.Server.tearDown."""
        # have asyncore release the channel
        self._ftp_server.del_channel()
        asyncore.close_all()
        self._async_thread.join()


del_channel() is from asyncore.dispatcher() which seems to close the
file handle.

Now the 'self._ftp_server.del_channel()' doesn't seem to effect much (I
can move it, or take it out altogether and I get the same traceback).

My best guess is that asyncore should be handling EBADF for us,
especially since we've called '.close_all()'.

So I'm wondering how to fix this. The EBADF is happening in the helper
thread.

The attached patch just makes the helper thread ignore EBADF, which
works for what I need.

Thoughts?

John
=:->
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ftp_ignore_ebadf.patch
Url: https://lists.ubuntu.com/archives/bazaar/attachments/20070412/d6dc7c7d/attachment.diff 


More information about the bazaar mailing list