diff mbox series

[5/7] server/process: Avoid dangling async commands

Message ID 20221221141543.497904-5-richard.purdie@linuxfoundation.org
State New
Headers show
Series [1/7] knotty: Ping the server/cooker periodically | expand

Commit Message

Richard Purdie Dec. 21, 2022, 2:15 p.m. UTC
There is a race where the client can have disconnected but the async
command hasn't finished running and isn't cleared up by the idle handler.
If a client connects and finds this state, it will fail as the server
appears busy and no new async command can execute. The old idle handler
code makes this unlikely but could explain some race issues. The new
code with idle handling in a separate thread makes it much more likely.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
 lib/bb/command.py        | 3 +++
 lib/bb/server/process.py | 1 +
 2 files changed, 4 insertions(+)
diff mbox series


diff --git a/lib/bb/command.py b/lib/bb/command.py
index 20a8b86653..1224eee413 100644
--- a/lib/bb/command.py
+++ b/lib/bb/command.py
@@ -152,6 +152,9 @@  class Command:
             bb.event.fire(CommandExit(code), self.cooker.data)
             bb.event.fire(CommandCompleted(), self.cooker.data)
+        self.finishAsyncDisconnect()
+    def finishAsyncDisconnect(self):
         self.currentAsyncCommand = None
diff --git a/lib/bb/server/process.py b/lib/bb/server/process.py
index 6f43330fae..c9984539e8 100644
--- a/lib/bb/server/process.py
+++ b/lib/bb/server/process.py
@@ -177,6 +177,7 @@  class ProcessServer():
                 self.command_channel = False
                 del self.event_writer
                 self.lastui = time.time()
+                self.cooker.command.finishAsyncDisconnect()
                 self.haveui = False
             ready = select.select(fds,[],[],0)[0]