Workaround twisted 8.x pipe-based waker
authorIustin Pop <iustin@google.com>
Tue, 10 Feb 2009 13:04:55 +0000 (13:04 +0000)
committerIustin Pop <iustin@google.com>
Tue, 10 Feb 2009 13:04:55 +0000 (13:04 +0000)
Twisted 8.x uses a waker objects for inter-thread signalling and the on
POSIX platforms the waker uses pipes for communication, which should not
be closed.

For some reasons, sometime the waker deals with its pipes being closed,
while at other times it doesn't. As such, we workaround it by skipping
the waker file descriptors in the utils.Daemonize function. This is
fragile and will break if Twisted changes internals, but it's a simple
workaround for now.

The patch also adds an assert in Daemonize() so that “standard” file
descriptors (0, 1, 2) are not marked to be kept open.

Reviewed-by: imsnah

daemons/ganeti-noded
lib/utils.py

index 58c3804..892db24 100755 (executable)
@@ -618,8 +618,15 @@ def main():
       sys.exit(5)
 
   # become a daemon
+  noclose_fds = []
+  if hasattr(reactor, 'waker'):
+    # twisted with waker object which has extra fds in use
+    for attr in ('i', 'o'):
+      val = getattr(reactor.waker, attr, None)
+      if isinstance(val, int):
+        noclose_fds.append(val)
   if options.fork:
-    utils.Daemonize(logfile=constants.LOG_NODESERVER)
+    utils.Daemonize(logfile=constants.LOG_NODESERVER, noclose_fds=noclose_fds)
 
   logger.SetupLogging(twisted_workaround=True, debug=options.debug,
                       program="ganeti-noded")
index 083fd2d..f6c00ee 100644 (file)
@@ -1160,6 +1160,7 @@ def Daemonize(logfile, noclose_fds=None):
   # Iterate through and close all file descriptors.
   for fd in range(0, maxfd):
     if noclose_fds and fd in noclose_fds:
+      assert fd > 2, "Cannot keep open standard fd %d" % fd
       continue
     try:
       os.close(fd)