fix(GODT-2458): Wait for both bridge and bridge-gui to be ended before restarting on crash.

This commit is contained in:
Romain Le Jeune 2023-03-07 15:44:58 +00:00
parent 59cf5e890b
commit 3ca56cfab3
3 changed files with 41 additions and 11 deletions

View File

@ -127,9 +127,11 @@ func main() { //nolint:funlen
l = l.WithField("exe_path", exe) l = l.WithField("exe_path", exe)
args, wait, mainExe := findAndStripWait(args) args, wait, mainExes := findAndStripWait(args)
if wait { if wait {
waitForProcessToFinish(mainExe) for _, mainExe := range mainExes {
waitForProcessToFinish(mainExe)
}
} }
cmd := execabs.Command(exe, appendLauncherPath(launcher, args)...) //nolint:gosec cmd := execabs.Command(exe, appendLauncherPath(launcher, args)...) //nolint:gosec
@ -186,12 +188,11 @@ func findAndStrip[T comparable](slice []T, v T) (strippedList []T, found bool) {
} }
// findAndStripWait Check for waiter flag get its value and clean them both. // findAndStripWait Check for waiter flag get its value and clean them both.
func findAndStripWait(args []string) ([]string, bool, string) { func findAndStripWait(args []string) ([]string, bool, []string) {
res := append([]string{}, args...) res := append([]string{}, args...)
hasFlag := false hasFlag := false
var value string values := make([]string, 0)
for k, v := range res { for k, v := range res {
if v != FlagWait { if v != FlagWait {
continue continue
@ -200,14 +201,16 @@ func findAndStripWait(args []string) ([]string, bool, string) {
continue continue
} }
hasFlag = true hasFlag = true
value = res[k+1] values = append(values, res[k+1])
} }
if hasFlag { if hasFlag {
res, _ = findAndStrip(res, FlagWait) res, _ = findAndStrip(res, FlagWait)
res, _ = findAndStrip(res, value) for _, v := range values {
res, _ = findAndStrip(res, v)
}
} }
return res, hasFlag, value return res, hasFlag, values
} }
func getPathToUpdatedExecutable( func getPathToUpdatedExecutable(

View File

@ -56,3 +56,25 @@ func TestFindAndStrip(t *testing.T) {
assert.False(t, found) assert.False(t, found)
assert.True(t, xslices.Equal(result, []string{})) assert.True(t, xslices.Equal(result, []string{}))
} }
func TestFindAndStripWait(t *testing.T) {
result, found, values := findAndStripWait([]string{"a", "b", "c"})
assert.False(t, found)
assert.True(t, xslices.Equal(result, []string{"a", "b", "c"}))
assert.True(t, xslices.Equal(values, []string{}))
result, found, values = findAndStripWait([]string{"a", "--wait", "b"})
assert.True(t, found)
assert.True(t, xslices.Equal(result, []string{"a"}))
assert.True(t, xslices.Equal(values, []string{"b"}))
result, found, values = findAndStripWait([]string{"a", "--wait", "b", "--wait", "c"})
assert.True(t, found)
assert.True(t, xslices.Equal(result, []string{"a"}))
assert.True(t, xslices.Equal(values, []string{"b", "c"}))
result, found, values = findAndStripWait([]string{"a", "--wait", "b", "--wait", "c", "--wait", "d"})
assert.True(t, found)
assert.True(t, xslices.Equal(result, []string{"a"}))
assert.True(t, xslices.Equal(values, []string{"b", "c", "d"}))
}

View File

@ -248,7 +248,7 @@ void focusOtherInstance() {
//**************************************************************************************************************************************************** //****************************************************************************************************************************************************
/// \param [in] args list of arguments to pass to bridge. /// \param [in] args list of arguments to pass to bridge.
//**************************************************************************************************************************************************** //****************************************************************************************************************************************************
void launchBridge(QStringList const &args) { const QString launchBridge(QStringList const &args) {
UPOverseer &overseer = app().bridgeOverseer(); UPOverseer &overseer = app().bridgeOverseer();
overseer.reset(); overseer.reset();
@ -265,6 +265,7 @@ void launchBridge(QStringList const &args) {
app().log().info(QString("Launching bridge process with command \"%1\" %2").arg(bridgeExePath, params.join(" "))); app().log().info(QString("Launching bridge process with command \"%1\" %2").arg(bridgeExePath, params.join(" ")));
overseer = std::make_unique<Overseer>(new ProcessMonitor(bridgeExePath, params, nullptr), nullptr); overseer = std::make_unique<Overseer>(new ProcessMonitor(bridgeExePath, params, nullptr), nullptr);
overseer->startWorker(true); overseer->startWorker(true);
return bridgeExePath;
} }
@ -330,7 +331,7 @@ int main(int argc, char *argv[]) {
// When not in attached mode, log entries are forwarded to bridge, which output it on stdout/stderr. bridge-gui's process monitor intercept // When not in attached mode, log entries are forwarded to bridge, which output it on stdout/stderr. bridge-gui's process monitor intercept
// these outputs and output them on the command-line. // these outputs and output them on the command-line.
log.setLevel(cliOptions.logLevel); log.setLevel(cliOptions.logLevel);
QString bridgeexec;
if (!cliOptions.attach) { if (!cliOptions.attach) {
if (isBridgeRunning()) { if (isBridgeRunning()) {
throw Exception("An orphan instance of bridge is already running. Please terminate it and relaunch the application.", throw Exception("An orphan instance of bridge is already running. Please terminate it and relaunch the application.",
@ -339,7 +340,7 @@ int main(int argc, char *argv[]) {
// before launching bridge, we remove any trailing service config file, because we need to make sure we get a newly generated one. // before launching bridge, we remove any trailing service config file, because we need to make sure we get a newly generated one.
GRPCClient::removeServiceConfigFile(); GRPCClient::removeServiceConfigFile();
launchBridge(cliOptions.bridgeArgs); bridgeexec = launchBridge(cliOptions.bridgeArgs);
} }
log.info(QString("Retrieving gRPC service configuration from '%1'").arg(QDir::toNativeSeparators(grpcServerConfigPath()))); log.info(QString("Retrieving gRPC service configuration from '%1'").arg(QDir::toNativeSeparators(grpcServerConfigPath())));
@ -401,6 +402,10 @@ int main(int argc, char *argv[]) {
QStringList args = cliOptions.bridgeGuiArgs; QStringList args = cliOptions.bridgeGuiArgs;
args.append(waitFlag); args.append(waitFlag);
args.append(mainexec); args.append(mainexec);
if (!bridgeexec.isEmpty()) {
args.append(waitFlag);
args.append(bridgeexec);
}
app().setLauncherArgs(cliOptions.launcher, args); app().setLauncherArgs(cliOptions.launcher, args);
result = QGuiApplication::exec(); result = QGuiApplication::exec();
} }