bitbake: process: Clean up connection retry logic

Its possible for a connection to connect to the server as its shutting down
but before its removed the socket file. This patch:

a) Removes the socket file earlier to avoid connections.
b) Handles EOFError in initial connections gracefully. These occur if the
   socket is closed during the server shutdown.
c) Ensure duplicate events aren't shown on the console. This makes debugging
   these issues very very confusing.

With these changes the backtrace that was concerning users is hidden and the
server works as expected with a reconnect when it catches it in a bad state.

(Bitbake rev: f45196cf84669723382730944dddc7eaf50826f2)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie
2017-08-23 15:46:00 +01:00
parent 95b99811bb
commit 2b453483d4
2 changed files with 14 additions and 7 deletions

View File

@@ -438,9 +438,10 @@ def setup_bitbake(configParams, configuration, extrafeatures=None):
return None, None return None, None
# we start a server with a given configuration # we start a server with a given configuration
logger.info("Starting bitbake server...") logger.info("Starting bitbake server...")
server = bb.server.process.BitBakeServer(lock, sockname, configuration, featureset) # Clear the event queue since we already displayed messages
# The server will handle any events already in the queue
bb.event.ui_queue = [] bb.event.ui_queue = []
server = bb.server.process.BitBakeServer(lock, sockname, configuration, featureset)
else: else:
logger.info("Reconnecting to bitbake server...") logger.info("Reconnecting to bitbake server...")
if not os.path.exists(sockname): if not os.path.exists(sockname):
@@ -448,7 +449,13 @@ def setup_bitbake(configParams, configuration, extrafeatures=None):
time.sleep(5) time.sleep(5)
raise bb.server.process.ProcessTimeout("Bitbake still shutting down as socket exists but no lock?") raise bb.server.process.ProcessTimeout("Bitbake still shutting down as socket exists but no lock?")
if not configParams.server_only: if not configParams.server_only:
try:
server_connection = bb.server.process.connectProcessServer(sockname, featureset) server_connection = bb.server.process.connectProcessServer(sockname, featureset)
except EOFError:
# The server may have been shutting down but not closed the socket yet. If that happened,
# ignore it.
pass
if server_connection or configParams.server_only: if server_connection or configParams.server_only:
break break
except (Exception, bb.server.process.ProcessTimeout) as e: except (Exception, bb.server.process.ProcessTimeout) as e:

View File

@@ -215,6 +215,10 @@ class ProcessServer(multiprocessing.Process):
ready = self.idle_commands(.1, fds) ready = self.idle_commands(.1, fds)
print("Exiting") print("Exiting")
# Remove the socket file so we don't get any more connections to avoid races
os.unlink(self.sockname)
self.sock.close()
try: try:
self.cooker.shutdown(True) self.cooker.shutdown(True)
except: except:
@@ -222,10 +226,6 @@ class ProcessServer(multiprocessing.Process):
self.cooker.post_serve() self.cooker.post_serve()
# Remove the socket file so we don't get any more connections to avoid races
os.unlink(self.sockname)
self.sock.close()
# Finally release the lockfile but warn about other processes holding it open # Finally release the lockfile but warn about other processes holding it open
lock = self.bitbake_lock lock = self.bitbake_lock
lockfile = lock.name lockfile = lock.name