From 9f8391e292f6e4ffd72437fcfb86afb42af33654 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 7 Feb 2019 12:57:58 +0200 Subject: Fix race in machine check --- bbot/agent/agent.cxx | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/bbot/agent/agent.cxx b/bbot/agent/agent.cxx index be3b706..83db6d7 100644 --- a/bbot/agent/agent.cxx +++ b/bbot/agent/agent.cxx @@ -263,7 +263,7 @@ bootstrap_machine (const dir_path& md, break; if (!check_machine ()) - return r; + return nullopt; } // This can mean two things: machine mis-configuration or what we @@ -301,6 +301,14 @@ bootstrap_machine (const dir_path& md, if (tftpd.serve (to, 2)) continue; + if (!check_machine ()) + { + // The exit/upload is racy so we re-check. + // + if (!(file_not_empty (mf) || file_not_empty (mfo))) + return nullopt; + } + bool old (false); if (file_not_empty (mf) || (old = file_not_empty (mfo))) { @@ -313,9 +321,6 @@ bootstrap_machine (const dir_path& md, if (!tftpd.serve (to, 5)) break; } - - if (!check_machine ()) - return nullopt; } if (to == 0) @@ -981,14 +986,17 @@ try if (tftpd.serve (to, 2)) continue; + if (!check_machine ()) + { + if (!file_not_empty (rf)) + return r; + } + if (file_not_empty (rf)) { if (!tftpd.serve (to, 5)) break; } - - if (!check_machine ()) - return r; } if (to == 0) -- cgit v1.1