feat: fix the graceful shutdown using the new ocis and reva runners

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Roman Perekhod
2025-05-12 23:15:07 +02:00
committed by Jörn Friedrich Dreyer
parent 7727c3ff1b
commit 65d05bbd5c
27 changed files with 935 additions and 838 deletions

View File

@@ -9,6 +9,7 @@ import (
ogrpc "github.com/opencloud-eu/opencloud/pkg/service/grpc"
ohttp "github.com/opencloud-eu/opencloud/pkg/service/http"
"github.com/opencloud-eu/reva/v2/cmd/revad/runtime"
"google.golang.org/grpc"
)
@@ -102,7 +103,8 @@ func NewGolangHttpServerRunner(name string, server *http.Server, opts ...Option)
// Since Shutdown might take some time, don't block
go func() {
// give 5 secs for the shutdown to finish
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
// TODO: To discuss the default timeout
shutdownCtx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
debugCh <- server.Shutdown(shutdownCtx)
@@ -132,3 +134,23 @@ func NewGolangGrpcServerRunner(name string, server *grpc.Server, listener net.Li
return r
}
func NewRevaServiceRunner(name string, server runtime.RevaDrivenServer, opts ...Option) *Runner {
httpCh := make(chan error, 1)
r := New(name, func() error {
// start the server and return if it fails
if err := server.Start(); err != nil {
return err
}
return <-httpCh // wait for the result
}, func() {
// stop implies deregistering and waiting for the request to finish,
// so don't block
go func() {
httpCh <- server.Stop() // stop and send a result through a channel
close(httpCh)
}()
}, opts...)
return r
}

View File

@@ -7,10 +7,12 @@ import (
var (
// DefaultInterruptDuration is the default value for the `WithInterruptDuration`
// for the "regular" runners. This global value can be adjusted if needed.
DefaultInterruptDuration = 10 * time.Second
// TODO: To discuss the default timeout
DefaultInterruptDuration = 20 * time.Second
// DefaultGroupInterruptDuration is the default value for the `WithInterruptDuration`
// for the group runners. This global value can be adjusted if needed.
DefaultGroupInterruptDuration = 15 * time.Second
// TODO: To discuss the default timeout
DefaultGroupInterruptDuration = 25 * time.Second
)
// Option defines a single option function.