$OpenBSD: patch-twisted_internet_process_py,v 1.2 2011/12/08 20:15:40 eric Exp $
--- twisted/internet/process.py.orig	Thu Nov 24 11:55:40 2011
+++ twisted/internet/process.py	Thu Nov 24 11:55:12 2011
@@ -501,7 +501,7 @@ class _FDDetector(object):
         This will try to return the fewest possible descriptors without missing
         any.
         """
-        self._listOpenFDs = self._getImplementation()
+        self._listOpenFDs = self._correctFDImplementation
         return self._listOpenFDs()
 
 
@@ -577,6 +577,16 @@ class _FDDetector(object):
             maxfds = min(1024, resource.getrlimit(resource.RLIMIT_NOFILE)[1])
         return range(maxfds)
 
+    def _correctFDImplementation(self):
+        import resource
+
+        maxfds = resource.getrlimit(resource.RLIMIT_NOFILE)[0]
+        fds = set(xrange(maxfds))
+        poll = select.poll()
+        for fd in fds:
+            poll.register(fd, select.POLLIN)
+        invals = set(f for (f, e) in poll.poll(0) if e == select.POLLNVAL)
+        return sorted(fds.difference(invals))
 
 
 detector = _FDDetector()
