Patchwork [bitbake-devel] serv.py: Fix hang when spawned dynamically with bitbake

login
register
mail settings
Submitter Jason Wessel
Date Aug. 27, 2013, 8:12 p.m.
Message ID <1377634375-13016-1-git-send-email-jason.wessel@windriver.com>
Download mbox | patch
Permalink /patch/56771/
State Accepted
Commit 972bc43e6d5b1207b944b3baa8f9805adb35dda7
Headers show

Comments

Jason Wessel - Aug. 27, 2013, 8:12 p.m.
The PRServer has the possibility to hang indefinitely blocking on a
semaphore processing a xmlrpc request to send an event back to the
main bitbake instance.  This was observed during a "bitbake -e" on a
heavily loaded machine and the main bitbake instance and cooker exited
before the PRServer emitted its first log.

The stack trace is provided below as to show what happens every time a
logger.info() is executed in the PRServer.  Not only does it write to
the stream handler but it also tries to send the event to the main
event processor.

    self._notempty.acquire()
    self.queue.put(event)
    _ui_handlers[h].event.send(event)
    fire_ui_handlers(event, d)
    fire(record, None)
    self.emit(record)
    hdlr.handle(record)
    self.callHandlers(record)
    self.handle(record)
    self._log(INFO, msg, args, **kwargs)
    (self.dbfile, self.host, self.port, str(os.getpid())))
    self.work_forever()
    pid = self.daemonize()
    self.prserv.start()
    singleton.start()
    self.prhost = prserv.serv.auto_start(self.data)
    cooker.pre_serve()
    bb.cooker.server_main(self.cooker, self.main)
    self.run()
    code = process_obj._bootstrap()
    self._popen = Popen(self)
    self.serverImpl.start()
    server.detach()
    server = start_server(servermodule, configParams, configuration)
    ret = main()

It was never intended for the PRServer to send its logs anywhere but
its own log file.  The event processing is an artifact of how the
PRServer was forked and it inherits the event log handlers.  The
simple fix is to clean up and purge all the log handlers after the
fork() but before doing any of the typical PRServer work or logging.

Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
---
 lib/prserv/serv.py |    5 +++++
 1 file changed, 5 insertions(+)

Patch

diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
index 81b4f8d..781f054 100644
--- a/lib/prserv/serv.py
+++ b/lib/prserv/serv.py
@@ -143,6 +143,11 @@  class PRServer(SimpleXMLRPCServer):
         os.dup2(so.fileno(),sys.stdout.fileno())
         os.dup2(se.fileno(),sys.stderr.fileno())
 
+        # Clear out all log handlers prior to the fork() to avoid calling
+        # event handlers not part of the PRserver
+        for logger_iter in logging.Logger.manager.loggerDict.keys():
+            logger_iter.handlers = []
+
         # Ensure logging makes it to the logfile
         streamhandler = logging.StreamHandler()
         streamhandler.setLevel(logging.DEBUG)