diff --git a/cmd/neofs-rest-gw/config.go b/cmd/neofs-rest-gw/config.go index aba4b6e..dbed486 100644 --- a/cmd/neofs-rest-gw/config.go +++ b/cmd/neofs-rest-gw/config.go @@ -33,7 +33,8 @@ const ( defaultHealthcheckTimeout = 15 * time.Second defaultRebalanceTimer = 60 * time.Second - defaultShutdownTimeout = 15 * time.Second + defaultShutdownTimeout = 15 * time.Second + defaultWaiterOperationTimeout = 1 * time.Minute defaultPoolErrorThreshold uint32 = 100 defaultPoolDefaultTimestamp bool = false @@ -596,6 +597,7 @@ func newNeofsAPI(ctx context.Context, logger *zap.Logger, v *viper.Viper) (*hand } apiPrm.DefaultTimestamp = v.GetBool(cfgPoolDefaultTimestamp) + apiPrm.WaiterOperationTimeout = defaultWaiterOperationTimeout return handlers.NewAPI(&apiPrm) } diff --git a/handlers/api.go b/handlers/api.go index 64c5771..12c534d 100644 --- a/handlers/api.go +++ b/handlers/api.go @@ -32,6 +32,7 @@ type PrmAPI struct { PrometheusService *metrics.Service PprofService *metrics.Service ServiceShutdownTimeout time.Duration + WaiterOperationTimeout time.Duration } type BearerToken struct { @@ -75,6 +76,7 @@ func NewAPI(prm *PrmAPI) (*RestAPI, error) { pprofService: prm.PprofService, gateMetric: prm.GateMetric, serviceShutdownTimeout: prm.ServiceShutdownTimeout, + waiterOperationTimeout: prm.WaiterOperationTimeout, }, nil } @@ -141,6 +143,7 @@ type RestAPI struct { prometheusService *metrics.Service pprofService *metrics.Service serviceShutdownTimeout time.Duration + waiterOperationTimeout time.Duration } func (a *RestAPI) StartCallback() { diff --git a/handlers/containers.go b/handlers/containers.go index 53c552d..106d8fb 100644 --- a/handlers/containers.go +++ b/handlers/containers.go @@ -64,7 +64,10 @@ func (a *RestAPI) PutContainer(ctx echo.Context, params apiserver.PutContainerPa return ctx.JSON(http.StatusBadRequest, resp) } - cnrID, err := createContainer(ctx.Request().Context(), a.pool, stoken, body, params, a.signer) + wCtx, cancel := context.WithTimeout(ctx.Request().Context(), a.waiterOperationTimeout) + defer cancel() + + cnrID, err := createContainer(wCtx, a.pool, stoken, body, params, a.signer) if err != nil { resp := a.logAndGetErrorResponse("create container", err) return ctx.JSON(http.StatusBadRequest, resp) @@ -136,7 +139,10 @@ func (a *RestAPI) PutContainerEACL(ctx echo.Context, containerID apiserver.Conta return ctx.JSON(http.StatusBadRequest, resp) } - if err = setContainerEACL(ctx.Request().Context(), a.pool, cnrID, stoken, body, a.signer); err != nil { + wCtx, cancel := context.WithTimeout(ctx.Request().Context(), a.waiterOperationTimeout) + defer cancel() + + if err = setContainerEACL(wCtx, a.pool, cnrID, stoken, body, a.signer); err != nil { resp := a.logAndGetErrorResponse("failed set container eacl", err) return ctx.JSON(http.StatusBadRequest, resp) } @@ -255,7 +261,10 @@ func (a *RestAPI) DeleteContainer(ctx echo.Context, containerID apiserver.Contai prm.WithinSession(stoken) wait := waiter.NewContainerDeleteWaiter(a.pool, waiter.DefaultPollInterval) - if err = wait.ContainerDelete(ctx.Request().Context(), cnrID, a.signer, prm); err != nil { + wCtx, cancel := context.WithTimeout(ctx.Request().Context(), a.waiterOperationTimeout) + defer cancel() + + if err = wait.ContainerDelete(wCtx, cnrID, a.signer, prm); err != nil { resp := a.logAndGetErrorResponse("delete container", err, zap.String("container", containerID)) return ctx.JSON(http.StatusBadRequest, resp) }