From e3e3d1ee579420abd71a2e9fa51e9de22eafaff1 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 6 Dec 2021 12:11:48 +0100 Subject: [PATCH 1/2] runtime: removed trap goroutine and let the context cancelation do the thing --- accounts/pkg/command/server.go | 6 ------ glauth/pkg/command/server.go | 5 ----- graph-explorer/pkg/command/server.go | 5 ----- graph/pkg/command/server.go | 5 ----- idp/pkg/command/server.go | 5 ----- ocis/pkg/command/storagemetadata.go | 1 - ocis/pkg/runtime/cmd/run.go | 3 ++- ocis/pkg/runtime/service/service.go | 12 ++---------- ocs/pkg/command/server.go | 6 ------ proxy/pkg/command/server.go | 5 ----- settings/pkg/command/server.go | 5 ----- store/pkg/command/server.go | 6 ------ thumbnails/pkg/command/server.go | 5 ----- web/pkg/command/server.go | 5 ----- webdav/pkg/command/server.go | 5 ----- 15 files changed, 4 insertions(+), 75 deletions(-) diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index 45298d298..e4e6f92e6 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -6,8 +6,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/log" - "github.com/owncloud/ocis/ocis-pkg/sync" - "github.com/oklog/run" "github.com/owncloud/ocis/accounts/pkg/config" "github.com/owncloud/ocis/accounts/pkg/metrics" @@ -85,10 +83,6 @@ func Server(cfg *config.Config) *cli.Command { cancel() }) - if !cfg.Supervised { - sync.Trap(&gr, cancel) - } - return gr.Run() }, } diff --git a/glauth/pkg/command/server.go b/glauth/pkg/command/server.go index d3e903503..d9cbb5f1c 100644 --- a/glauth/pkg/command/server.go +++ b/glauth/pkg/command/server.go @@ -14,7 +14,6 @@ import ( "github.com/owncloud/ocis/glauth/pkg/tracing" pkgcrypto "github.com/owncloud/ocis/ocis-pkg/crypto" "github.com/owncloud/ocis/ocis-pkg/service/grpc" - "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/urfave/cli/v2" ) @@ -178,10 +177,6 @@ func Server(cfg *config.Config) *cli.Command { }) } - if !cfg.Supervised { - sync.Trap(&gr, cancel) - } - return gr.Run() }, } diff --git a/graph-explorer/pkg/command/server.go b/graph-explorer/pkg/command/server.go index f97daa3b8..86dabfe32 100644 --- a/graph-explorer/pkg/command/server.go +++ b/graph-explorer/pkg/command/server.go @@ -10,7 +10,6 @@ import ( "github.com/owncloud/ocis/graph-explorer/pkg/server/debug" "github.com/owncloud/ocis/graph-explorer/pkg/server/http" "github.com/owncloud/ocis/graph-explorer/pkg/tracing" - "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/urfave/cli/v2" ) @@ -95,10 +94,6 @@ func Server(cfg *config.Config) *cli.Command { }) } - if !cfg.Supervised { - sync.Trap(&gr, cancel) - } - return gr.Run() }, } diff --git a/graph/pkg/command/server.go b/graph/pkg/command/server.go index 1c4341bcc..32cd2a4ab 100644 --- a/graph/pkg/command/server.go +++ b/graph/pkg/command/server.go @@ -10,7 +10,6 @@ import ( "github.com/owncloud/ocis/graph/pkg/server/debug" "github.com/owncloud/ocis/graph/pkg/server/http" "github.com/owncloud/ocis/graph/pkg/tracing" - "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/urfave/cli/v2" ) @@ -92,10 +91,6 @@ func Server(cfg *config.Config) *cli.Command { }) } - if !cfg.Supervised { - sync.Trap(&gr, cancel) - } - return gr.Run() }, } diff --git a/idp/pkg/command/server.go b/idp/pkg/command/server.go index c9f943ebc..d3b62034f 100644 --- a/idp/pkg/command/server.go +++ b/idp/pkg/command/server.go @@ -10,7 +10,6 @@ import ( "github.com/owncloud/ocis/idp/pkg/server/debug" "github.com/owncloud/ocis/idp/pkg/server/http" "github.com/owncloud/ocis/idp/pkg/tracing" - "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/urfave/cli/v2" ) @@ -96,10 +95,6 @@ func Server(cfg *config.Config) *cli.Command { }) } - if !cfg.Supervised { - sync.Trap(&gr, cancel) - } - return gr.Run() }, } diff --git a/ocis/pkg/command/storagemetadata.go b/ocis/pkg/command/storagemetadata.go index d475da582..59598a245 100644 --- a/ocis/pkg/command/storagemetadata.go +++ b/ocis/pkg/command/storagemetadata.go @@ -13,7 +13,6 @@ func StorageMetadataCommand(cfg *config.Config) *cli.Command { Name: "storage-metadata", Usage: "Start storage and data service for metadata", Category: "Extensions", - //Flags: flagset.StorageMetadata(cfg.Storage), Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/runtime/cmd/run.go b/ocis/pkg/runtime/cmd/run.go index 1c977b0fc..c529d3764 100644 --- a/ocis/pkg/runtime/cmd/run.go +++ b/ocis/pkg/runtime/cmd/run.go @@ -22,7 +22,8 @@ func Run(cfg *config.Config) *cobra.Command { log.Fatal("dialing:", err) } var res int - if err := client.Call("Service.Start", &args[0], &res); err != nil { + + if err = client.Call("Service.Start", &args[0], &res); err != nil { log.Fatal(err) } diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index a725b04bf..2def6c6f5 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -137,9 +137,6 @@ func Start(o ...Option) error { halt := make(chan os.Signal, 1) signal.Notify(halt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) - // notify goroutines that they are running on supervised mode - s.cfg.Mode = ociscfg.SUPERVISED - setMicroLogger() // tolerance controls backoff cycles from the supervisor. @@ -191,7 +188,7 @@ func Start(o ...Option) error { defer func() { if r := recover(); r != nil { reason := strings.Builder{} - if _, err := net.Dial("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)); err != nil { + if _, err = net.Dial("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)); err != nil { reason.WriteString("runtime address already in use") } @@ -256,11 +253,6 @@ func (s *Service) generateRunSet(cfg *config.Config) { // Start indicates the Service Controller to start a new supervised service as an OS thread. func (s *Service) Start(name string, reply *int) error { - // RPC calls to a Service object will allow for parsing config. Mind that since the runtime is running on a different - // machine, the configuration needs to be present in the given machine. RPC does not yet allow providing a config - // during transport. - s.cfg.Mode = ociscfg.UNSUPERVISED - swap := deepcopy.Copy(s.cfg) if _, ok := s.ServicesRegistry[name]; ok { *reply = 0 @@ -306,7 +298,7 @@ func (s *Service) List(args struct{}, reply *string) error { func (s *Service) Kill(name string, reply *int) error { if len(s.serviceToken[name]) > 0 { for i := range s.serviceToken[name] { - if err := s.Supervisor.Remove(s.serviceToken[name][i]); err != nil { + if err := s.Supervisor.RemoveAndWait(s.serviceToken[name][i], 5000*time.Millisecond); err != nil { return err } } diff --git a/ocs/pkg/command/server.go b/ocs/pkg/command/server.go index 722673cd1..d72e96216 100644 --- a/ocs/pkg/command/server.go +++ b/ocs/pkg/command/server.go @@ -6,8 +6,6 @@ import ( "github.com/owncloud/ocis/ocs/pkg/tracing" - "github.com/owncloud/ocis/ocis-pkg/sync" - "github.com/oklog/run" "github.com/owncloud/ocis/ocs/pkg/config" "github.com/owncloud/ocis/ocs/pkg/metrics" @@ -100,10 +98,6 @@ func Server(cfg *config.Config) *cli.Command { }) } - if !cfg.Supervised { - sync.Trap(&gr, cancel) - } - return gr.Run() }, } diff --git a/proxy/pkg/command/server.go b/proxy/pkg/command/server.go index fbc26bc39..ed8e2d9c0 100644 --- a/proxy/pkg/command/server.go +++ b/proxy/pkg/command/server.go @@ -18,7 +18,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/log" pkgmiddleware "github.com/owncloud/ocis/ocis-pkg/middleware" "github.com/owncloud/ocis/ocis-pkg/service/grpc" - "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/proxy/pkg/config" "github.com/owncloud/ocis/proxy/pkg/cs3" "github.com/owncloud/ocis/proxy/pkg/metrics" @@ -138,10 +137,6 @@ func Server(cfg *config.Config) *cli.Command { }) } - if !cfg.Supervised { - sync.Trap(&gr, cancel) - } - return gr.Run() }, } diff --git a/settings/pkg/command/server.go b/settings/pkg/command/server.go index 894b159ff..bd430f263 100644 --- a/settings/pkg/command/server.go +++ b/settings/pkg/command/server.go @@ -5,7 +5,6 @@ import ( "strings" "github.com/oklog/run" - "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/settings/pkg/config" "github.com/owncloud/ocis/settings/pkg/metrics" "github.com/owncloud/ocis/settings/pkg/server/debug" @@ -83,10 +82,6 @@ func Server(cfg *config.Config) *cli.Command { cancel() }) - if !cfg.Supervised { - sync.Trap(&servers, cancel) - } - return servers.Run() }, } diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index 622719874..4bc9b35b9 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -9,8 +9,6 @@ import ( "github.com/owncloud/ocis/store/pkg/tracing" - "github.com/owncloud/ocis/ocis-pkg/sync" - "github.com/oklog/run" "github.com/owncloud/ocis/store/pkg/config" "github.com/owncloud/ocis/store/pkg/metrics" @@ -103,10 +101,6 @@ func Server(cfg *config.Config) *cli.Command { }) } - if !cfg.Supervised { - sync.Trap(&gr, cancel) - } - return gr.Run() }, } diff --git a/thumbnails/pkg/command/server.go b/thumbnails/pkg/command/server.go index e929245a4..fc7ec10a6 100644 --- a/thumbnails/pkg/command/server.go +++ b/thumbnails/pkg/command/server.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/oklog/run" - "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/thumbnails/pkg/config" "github.com/owncloud/ocis/thumbnails/pkg/metrics" "github.com/owncloud/ocis/thumbnails/pkg/server/debug" @@ -78,10 +77,6 @@ func Server(cfg *config.Config) *cli.Command { cancel() }) - if !cfg.Supervised { - sync.Trap(&gr, cancel) - } - return gr.Run() }, } diff --git a/web/pkg/command/server.go b/web/pkg/command/server.go index a0a11f37d..c8b8fd107 100644 --- a/web/pkg/command/server.go +++ b/web/pkg/command/server.go @@ -7,7 +7,6 @@ import ( "strings" "github.com/oklog/run" - "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/web/pkg/config" "github.com/owncloud/ocis/web/pkg/metrics" "github.com/owncloud/ocis/web/pkg/server/debug" @@ -124,10 +123,6 @@ func Server(cfg *config.Config) *cli.Command { }) } - if !cfg.Supervised { - sync.Trap(&gr, cancel) - } - return gr.Run() }, } diff --git a/webdav/pkg/command/server.go b/webdav/pkg/command/server.go index c0248c5a0..d3f68efcf 100644 --- a/webdav/pkg/command/server.go +++ b/webdav/pkg/command/server.go @@ -5,7 +5,6 @@ import ( "strings" "github.com/oklog/run" - "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/webdav/pkg/config" "github.com/owncloud/ocis/webdav/pkg/metrics" "github.com/owncloud/ocis/webdav/pkg/server/debug" @@ -100,10 +99,6 @@ func Server(cfg *config.Config) *cli.Command { }) } - if !cfg.Supervised { - sync.Trap(&gr, cancel) - } - return gr.Run() }, } From 8f14fdae1cbf5e4f7a115cc79df92e43efd3a0eb Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 6 Dec 2021 13:56:57 +0100 Subject: [PATCH 2/2] added changelog --- changelog/unreleased/supervisor-stop-routine.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/unreleased/supervisor-stop-routine.md diff --git a/changelog/unreleased/supervisor-stop-routine.md b/changelog/unreleased/supervisor-stop-routine.md new file mode 100644 index 000000000..7c4ecb2b8 --- /dev/null +++ b/changelog/unreleased/supervisor-stop-routine.md @@ -0,0 +1,5 @@ +Enhancement: Correct shutdown of services under runtime + +Supervised goroutines now shut themselves down on context cancellation propagation. + +https://github.com/owncloud/ocis/pull/2843