summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2014-11-04 14:02:32 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-12-31 10:09:50 +0000
commit08cf468ab751f4c6e4ffdab2d8e5d748f7698593 (patch)
treed27c3d27d8c1d550bb0509faf2ea99cce85dafd1
parent973ac2cc63323ca9c3e916effa4765747db3564c (diff)
downloadbitbake-08cf468ab751f4c6e4ffdab2d8e5d748f7698593.tar.gz
prserv/serv: Ensure sync happens in the correct thread
The sync/commit calls are happening in the submission thread which can race against the handler. The handler may start new transactions which then causes the submission thread to error with "cannot start a transaction within a transaction". The fix is to move the calls to the correct thread. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--lib/prserv/serv.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
index 6ab10972e..25eb46a41 100644
--- a/lib/prserv/serv.py
+++ b/lib/prserv/serv.py
@@ -76,11 +76,19 @@ class PRServer(SimpleXMLRPCServer):
In addition, exception handling is done here.
"""
+ iter_count = 1
+ # With 60 iterations between syncs and a 0.5 second timeout between
+ # iterations, this will sync if dirty every ~30 seconds.
+ iterations_between_sync = 60
+
while True:
(request, client_address) = self.requestqueue.get()
try:
self.finish_request(request, client_address)
self.shutdown_request(request)
+ iter_count = (iter_count + 1) % iterations_between_sync
+ if iter_count == 0:
+ self.table.sync_if_dirty()
except:
self.handle_error(request, client_address)
self.shutdown_request(request)
@@ -122,10 +130,6 @@ class PRServer(SimpleXMLRPCServer):
def work_forever(self,):
self.quit = False
self.timeout = 0.5
- iter_count = 1
- # With 60 iterations between syncs and a 0.5 second timeout between
- # iterations, this will sync if dirty every ~30 seconds.
- iterations_between_sync = 60
logger.info("Started PRServer with DBfile: %s, IP: %s, PORT: %s, PID: %s" %
(self.dbfile, self.host, self.port, str(os.getpid())))
@@ -133,9 +137,6 @@ class PRServer(SimpleXMLRPCServer):
self.handlerthread.start()
while not self.quit:
self.handle_request()
- iter_count = (iter_count + 1) % iterations_between_sync
- if iter_count == 0:
- self.table.sync_if_dirty()
self.table.sync()
logger.info("PRServer: stopping...")