diff --git a/pkg/visor/rpc_test.go b/pkg/visor/rpc_test.go index 9f13e0e65e..b64ed85c34 100644 --- a/pkg/visor/rpc_test.go +++ b/pkg/visor/rpc_test.go @@ -1,6 +1,7 @@ package visor import ( + "errors" "fmt" "net/http" "os" @@ -124,7 +125,7 @@ func TestStartStopApp(t *testing.T) { err = rpc.StopApp(&unknownApp, nil) require.Error(t, err) - assert.Equal(t, ErrUnknownApp, err) + assert.Equal(t, errors.New("app is either non-existent, or is already stopped"), err) require.NoError(t, rpc.StopApp(&app, nil)) time.Sleep(100 * time.Millisecond) diff --git a/pkg/visor/visor.go b/pkg/visor/visor.go index 5e82dbf375..f2e1979664 100644 --- a/pkg/visor/visor.go +++ b/pkg/visor/visor.go @@ -400,18 +400,25 @@ func (node *Node) Apps() []*AppState { // StartApp starts registered App. func (node *Node) StartApp(appName string) error { - for _, app := range node.appsConf { - if app.App == appName { - startCh := make(chan struct{}) - go func(app AppConfig) { - if err := node.SpawnApp(&app, startCh); err != nil { - node.logger.Warnf("Failed to start app %s: %s", appName, err) - } - }(app) - - <-startCh - return nil + for _, appC := range node.appsConf { + if appC.App != appName { + continue } + + done := make(chan struct{}, 1) + var err error + + go func(appC AppConfig) { + if err = node.SpawnApp(&appC, done); err != nil { + done <- struct{}{} + node.logger.Warnf("Failed to start app %s: %s", appName, err) + } + }(appC) + + <-done + close(done) + + return err } return ErrUnknownApp