On Mon, Feb 02, 2009 at 02:39:30PM +0100, Daniel Schreiber wrote: > Iustin Pop schrieb: >> Thanks for confirming. I have a patch that might or might not solve the >> problem, since I don't know how early twisted creates the pipes. Would >> you mind testing the attached patch? (Will be a little bit tricky to >> apply to installed sources though). >> >> If the patch doesn't solve the problem, then we will have to implement >> an option to not close file descriptors for Ganeti 1.2. > > Unfortunately it doesn't solve the problem. I put the patch into > debian/patches, rebuilt the package and installed it. Verified that the > patched files were installed.
OK, then the only other option beside not closing any file descriptors is to dig into the twisted 8.x reactor/waker types and extract their file descriptors. Would you mind trying this new patch? And thanks a lot for your debugging :) regards, iustin
>From be4f6326f78fd6053ac1faa46c57d338b69afb64 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iu...@k1024.org> Date: Tue, 3 Feb 2009 21:11:19 +0100 Subject: [PATCH] Workaround twisted 8.x pipe-based waker MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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. --- daemons/ganeti-noded | 9 ++++++++- lib/utils.py | 1 + 2 files changed, 9 insertions(+), 1 deletions(-) diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded index 58c3804..892db24 100755 --- a/daemons/ganeti-noded +++ b/daemons/ganeti-noded @@ -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") diff --git a/lib/utils.py b/lib/utils.py index 083fd2d..f6c00ee 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -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) -- 1.5.6.5