aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2023-01-14 04:12:02 -1000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-01-16 11:08:34 +0000
commit52b6b099a47555811b8d0b311f62af712dd6eb8e (patch)
tree8b56c0fca75bf42e140ec79da693652e2cee8acb
parent9779fad4d9e2540b24bb91cfa38fc1984402bef2 (diff)
downloadbitbake-52b6b099a47555811b8d0b311f62af712dd6eb8e.tar.gz
server/process: Add bitbake.sock race handling
We've seen cases where the bitbake.sock file appears to disappear but the server continues to hold bitbake.lock. The most likely explaination is that some previous build directory was moved out the way, a server there kept running, eventually exited and removed the sock file from the wrong directory. To guard against this, save the inode information for the sock file and check it before deleting the file. The new code isn't entirely race free but should guard against what is a rare but annoying potential issue. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit b02ebbffdae27e564450446bf84c4e98d094ee4a) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--lib/bb/server/process.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/bb/server/process.py b/lib/bb/server/process.py
index 2a9fb6623..3668a32b7 100644
--- a/lib/bb/server/process.py
+++ b/lib/bb/server/process.py
@@ -28,6 +28,7 @@ import datetime
import pickle
import traceback
import gc
+import stat
import bb.server.xmlrpcserver
from bb import daemonize
from multiprocessing import queues
@@ -64,6 +65,9 @@ class ProcessServer():
self.bitbake_lock_name = lockname
self.sock = sock
self.sockname = sockname
+ # It is possible the directory may be renamed. Cache the inode of the socket file
+ # so we can tell if things changed.
+ self.sockinode = os.stat(self.sockname)[stat.ST_INO]
self.server_timeout = server_timeout
self.timeout = self.server_timeout
@@ -246,8 +250,14 @@ class ProcessServer():
serverlog("Exiting")
# Remove the socket file so we don't get any more connections to avoid races
+ # The build directory could have been renamed so if the file isn't the one we created
+ # we shouldn't delete it.
try:
- os.unlink(self.sockname)
+ sockinode = os.stat(self.sockname)[stat.ST_INO]
+ if sockinode == self.sockinode:
+ os.unlink(self.sockname)
+ else:
+ serverlog("bitbake.sock inode mismatch (%s vs %s), not deleting." % (sockinode, self.sockinode))
except Exception as err:
serverlog("Removing socket file '%s' failed (%s)" % (self.sockname, err))
self.sock.close()