From d0d221a476191db220c689f5de5bd577f879c2b6 Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Wed, 9 Dec 2020 20:28:17 +0300 Subject: [PATCH 1/6] Pass cmd args from conf, not from the previous app start --- pkg/app/appserver/proc.go | 2 ++ pkg/app/appserver/proc_manager.go | 2 ++ pkg/app/launcher/launcher.go | 4 ++-- pkg/visor/api.go | 2 ++ pkg/visor/hypervisor.go | 1 + pkg/visor/visorconfig/v1.go | 5 +++++ 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/app/appserver/proc.go b/pkg/app/appserver/proc.go index 855077b55e..14deff4433 100644 --- a/pkg/app/appserver/proc.go +++ b/pkg/app/appserver/proc.go @@ -58,6 +58,8 @@ func NewProc(mLog *logging.MasterLogger, conf appcommon.ProcConfig, disc appdisc } moduleName := fmt.Sprintf("proc:%s:%s", conf.AppName, conf.ProcKey) + fmt.Printf("CONF PROC ARGS: %v\n", conf.ProcArgs) + cmd := exec.Command(conf.BinaryLoc, conf.ProcArgs...) // nolint:gosec cmd.Dir = conf.ProcWorkDir cmd.Env = append(os.Environ(), conf.Envs()...) diff --git a/pkg/app/appserver/proc_manager.go b/pkg/app/appserver/proc_manager.go index 05e64bca03..436cc37b74 100644 --- a/pkg/app/appserver/proc_manager.go +++ b/pkg/app/appserver/proc_manager.go @@ -169,6 +169,8 @@ func (m *procManager) Start(conf appcommon.ProcConfig) (appcommon.ProcID, error) m.mx.Lock() defer m.mx.Unlock() + m.log.Infof("APP ARGS INSIDE PROC MANAGER START: %v", conf.ProcArgs) + log := m.mLog.PackageLogger("proc:" + conf.AppName + ":" + conf.ProcKey.String()) // isDone should be called within the protection of a mutex. diff --git a/pkg/app/launcher/launcher.go b/pkg/app/launcher/launcher.go index 4a059579a2..f5a6941802 100644 --- a/pkg/app/launcher/launcher.go +++ b/pkg/app/launcher/launcher.go @@ -208,6 +208,7 @@ func (l *Launcher) startApp(cmd string, args, envs []string) error { if !ok { return ErrAppNotFound } + fmt.Printf("INITIAL APP ARGS: %v\n", ac.Args) if args != nil { ac.Args = args } @@ -260,8 +261,7 @@ func (l *Launcher) RestartApp(name string) error { } cmd := proc.Cmd() - // complete list of args includes binary name which is not needed, so omit it - if err := l.StartApp(name, cmd.Args[1:], cmd.Env); err != nil { + if err := l.StartApp(name, nil, cmd.Env); err != nil { return fmt.Errorf("failed to start %s: %w", name, err) } diff --git a/pkg/visor/api.go b/pkg/visor/api.go index 3acfb48017..2137de1cbc 100644 --- a/pkg/visor/api.go +++ b/pkg/visor/api.go @@ -249,6 +249,8 @@ func (v *Visor) StartApp(appName string) error { } } + v.log.Infoln("INSIDE START APP") + return v.appL.StartApp(appName, nil, envs) } diff --git a/pkg/visor/hypervisor.go b/pkg/visor/hypervisor.go index 790e1d3805..43ae0cbd97 100644 --- a/pkg/visor/hypervisor.go +++ b/pkg/visor/hypervisor.go @@ -549,6 +549,7 @@ func (hv *Hypervisor) putApp() http.HandlerFunc { } if reqBody.PK != nil { + log.Infof("SETTING REMOTE PK: %s", (*reqBody.PK).Hex()) if err := ctx.API.SetAppPK(ctx.App.Name, *reqBody.PK); err != nil { httputil.WriteJSON(w, r, http.StatusInternalServerError, err) return diff --git a/pkg/visor/visorconfig/v1.go b/pkg/visor/visorconfig/v1.go index d7d00c707a..e209631d57 100644 --- a/pkg/visor/visorconfig/v1.go +++ b/pkg/visor/visorconfig/v1.go @@ -1,6 +1,7 @@ package visorconfig import ( + "fmt" "sync" "github.com/skycoin/dmsg/cipher" @@ -134,6 +135,8 @@ func (v1 *V1) UpdateAppArg(launch *launcher.Launcher, appName, argName, value st v1.mu.Lock() defer v1.mu.Unlock() + fmt.Println("INSIDE UPDATE APP ARG") + conf := v1.Launcher configChanged := updateArg(conf, appName, argName, value) @@ -142,6 +145,8 @@ func (v1 *V1) UpdateAppArg(launch *launcher.Launcher, appName, argName, value st return nil } + fmt.Printf("ARGS AFTER CHANGING CONFIG: %v\n", conf.Apps) + launch.ResetConfig(launcher.Config{ VisorPK: v1.PK, Apps: conf.Apps, From 6aa0541506ecfacbfa0b87cb9bdc835fb6b87d41 Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Wed, 9 Dec 2020 20:34:16 +0300 Subject: [PATCH 2/6] Remove debug logs --- pkg/app/appserver/proc.go | 2 -- pkg/app/appserver/proc_manager.go | 2 -- pkg/app/launcher/launcher.go | 2 +- pkg/visor/api.go | 2 -- pkg/visor/hypervisor.go | 1 - pkg/visor/visorconfig/v1.go | 5 ----- 6 files changed, 1 insertion(+), 13 deletions(-) diff --git a/pkg/app/appserver/proc.go b/pkg/app/appserver/proc.go index 14deff4433..855077b55e 100644 --- a/pkg/app/appserver/proc.go +++ b/pkg/app/appserver/proc.go @@ -58,8 +58,6 @@ func NewProc(mLog *logging.MasterLogger, conf appcommon.ProcConfig, disc appdisc } moduleName := fmt.Sprintf("proc:%s:%s", conf.AppName, conf.ProcKey) - fmt.Printf("CONF PROC ARGS: %v\n", conf.ProcArgs) - cmd := exec.Command(conf.BinaryLoc, conf.ProcArgs...) // nolint:gosec cmd.Dir = conf.ProcWorkDir cmd.Env = append(os.Environ(), conf.Envs()...) diff --git a/pkg/app/appserver/proc_manager.go b/pkg/app/appserver/proc_manager.go index 436cc37b74..05e64bca03 100644 --- a/pkg/app/appserver/proc_manager.go +++ b/pkg/app/appserver/proc_manager.go @@ -169,8 +169,6 @@ func (m *procManager) Start(conf appcommon.ProcConfig) (appcommon.ProcID, error) m.mx.Lock() defer m.mx.Unlock() - m.log.Infof("APP ARGS INSIDE PROC MANAGER START: %v", conf.ProcArgs) - log := m.mLog.PackageLogger("proc:" + conf.AppName + ":" + conf.ProcKey.String()) // isDone should be called within the protection of a mutex. diff --git a/pkg/app/launcher/launcher.go b/pkg/app/launcher/launcher.go index f5a6941802..f864bc3564 100644 --- a/pkg/app/launcher/launcher.go +++ b/pkg/app/launcher/launcher.go @@ -208,7 +208,7 @@ func (l *Launcher) startApp(cmd string, args, envs []string) error { if !ok { return ErrAppNotFound } - fmt.Printf("INITIAL APP ARGS: %v\n", ac.Args) + if args != nil { ac.Args = args } diff --git a/pkg/visor/api.go b/pkg/visor/api.go index 2137de1cbc..3acfb48017 100644 --- a/pkg/visor/api.go +++ b/pkg/visor/api.go @@ -249,8 +249,6 @@ func (v *Visor) StartApp(appName string) error { } } - v.log.Infoln("INSIDE START APP") - return v.appL.StartApp(appName, nil, envs) } diff --git a/pkg/visor/hypervisor.go b/pkg/visor/hypervisor.go index 43ae0cbd97..790e1d3805 100644 --- a/pkg/visor/hypervisor.go +++ b/pkg/visor/hypervisor.go @@ -549,7 +549,6 @@ func (hv *Hypervisor) putApp() http.HandlerFunc { } if reqBody.PK != nil { - log.Infof("SETTING REMOTE PK: %s", (*reqBody.PK).Hex()) if err := ctx.API.SetAppPK(ctx.App.Name, *reqBody.PK); err != nil { httputil.WriteJSON(w, r, http.StatusInternalServerError, err) return diff --git a/pkg/visor/visorconfig/v1.go b/pkg/visor/visorconfig/v1.go index e209631d57..d7d00c707a 100644 --- a/pkg/visor/visorconfig/v1.go +++ b/pkg/visor/visorconfig/v1.go @@ -1,7 +1,6 @@ package visorconfig import ( - "fmt" "sync" "github.com/skycoin/dmsg/cipher" @@ -135,8 +134,6 @@ func (v1 *V1) UpdateAppArg(launch *launcher.Launcher, appName, argName, value st v1.mu.Lock() defer v1.mu.Unlock() - fmt.Println("INSIDE UPDATE APP ARG") - conf := v1.Launcher configChanged := updateArg(conf, appName, argName, value) @@ -145,8 +142,6 @@ func (v1 *V1) UpdateAppArg(launch *launcher.Launcher, appName, argName, value st return nil } - fmt.Printf("ARGS AFTER CHANGING CONFIG: %v\n", conf.Apps) - launch.ResetConfig(launcher.Config{ VisorPK: v1.PK, Apps: conf.Apps, From fd89cfaec1ae547c9de63ed30bf2f28d32bfea82 Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Wed, 9 Dec 2020 21:01:35 +0300 Subject: [PATCH 3/6] Temporarily remove VPN client auto reconnection --- internal/vpn/client.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/vpn/client.go b/internal/vpn/client.go index 52ec5510cb..aafbd730a0 100644 --- a/internal/vpn/client.go +++ b/internal/vpn/client.go @@ -181,6 +181,8 @@ func (c *Client) Serve() error { fmt.Printf("dialServeConn: %v\n", err) } + return errors.New("fail") + if c.isClosed() { return nil } From 3e866b00b795398edcfe116a01c6dc908eece17b Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Wed, 9 Dec 2020 22:00:18 +0300 Subject: [PATCH 4/6] Properly delete app from the manager when it gets closed for any reason --- pkg/app/appserver/proc.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/app/appserver/proc.go b/pkg/app/appserver/proc.go index 855077b55e..383f76d52b 100644 --- a/pkg/app/appserver/proc.go +++ b/pkg/app/appserver/proc.go @@ -162,6 +162,13 @@ func (p *Proc) Start() error { close(waitErrCh) }() + defer func() { + // here will definitely be an error notifying that the process + // is already stopped. We do this to remove proc from the manager, + // therefore giving the correct app status to hypervisor. + _ = p.m.Stop(p.appName) //nolint:errcheck + }() + select { case _, ok := <-p.connCh: if !ok { @@ -181,23 +188,23 @@ func (p *Proc) Start() error { // channel won't get closed outside, close it now. p.connOnce.Do(func() { close(p.connCh) }) - // here will definitely be an error notifying that the process - // is already stopped. We do this to remove proc from the manager, - // therefore giving the correct app status to hypervisor. - _ = p.m.Stop(p.appName) //nolint:errcheck - return } // here, the connection is established, so we're not blocked by awaiting it anymore, // execution may be continued as usual. + p.log.Infoln("AWAITING CONN") + if ok := p.awaitConn(); !ok { + p.log.Infoln("ERROR AWAITING CONN") _ = p.cmd.Process.Kill() //nolint:errcheck p.waitMx.Unlock() return } + p.log.Infoln("AWAITED CONN") + // App discovery start/stop. p.disc.Start() defer p.disc.Stop() @@ -205,6 +212,8 @@ func (p *Proc) Start() error { // Wait for proc to exit. p.waitErr = <-waitErrCh + p.log.Infof("GOT ERR: %v", p.waitErr) + // Close proc conn and associated listeners and connections. if err := p.conn.Close(); err != nil && !strings.Contains(err.Error(), "use of closed network connection") { p.log.WithError(err).Warn("Closing proc conn returned unexpected error.") From ff56fd76129272318a90ca42d79c0d5ccfaf7c03 Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Wed, 9 Dec 2020 22:01:32 +0300 Subject: [PATCH 5/6] Remove debug logs --- pkg/app/appserver/proc.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pkg/app/appserver/proc.go b/pkg/app/appserver/proc.go index 383f76d52b..5ae26d4ce8 100644 --- a/pkg/app/appserver/proc.go +++ b/pkg/app/appserver/proc.go @@ -194,17 +194,12 @@ func (p *Proc) Start() error { // here, the connection is established, so we're not blocked by awaiting it anymore, // execution may be continued as usual. - p.log.Infoln("AWAITING CONN") - if ok := p.awaitConn(); !ok { - p.log.Infoln("ERROR AWAITING CONN") _ = p.cmd.Process.Kill() //nolint:errcheck p.waitMx.Unlock() return } - p.log.Infoln("AWAITED CONN") - // App discovery start/stop. p.disc.Start() defer p.disc.Stop() @@ -212,8 +207,6 @@ func (p *Proc) Start() error { // Wait for proc to exit. p.waitErr = <-waitErrCh - p.log.Infof("GOT ERR: %v", p.waitErr) - // Close proc conn and associated listeners and connections. if err := p.conn.Close(); err != nil && !strings.Contains(err.Error(), "use of closed network connection") { p.log.WithError(err).Warn("Closing proc conn returned unexpected error.") From 3411998502cbf5fe9a868077fa6aa3f6f519ca4d Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Wed, 9 Dec 2020 22:01:53 +0300 Subject: [PATCH 6/6] Get auto reconnection back --- internal/vpn/client.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/vpn/client.go b/internal/vpn/client.go index aafbd730a0..52ec5510cb 100644 --- a/internal/vpn/client.go +++ b/internal/vpn/client.go @@ -181,8 +181,6 @@ func (c *Client) Serve() error { fmt.Printf("dialServeConn: %v\n", err) } - return errors.New("fail") - if c.isClosed() { return nil }