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
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")
# 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)