From 953bfc76b2ea361e67c70adb1e3c6e3f91578985 Mon Sep 17 00:00:00 2001 From: Randall Leeds Date: Mon, 10 Feb 2025 17:14:30 -0800 Subject: [PATCH] fix: cgroups auto-tune before driver configuration Move the cgroups auto-tuning into the driver factory so that its effect is automatically applied to the database connection pool defaults. BREAKING CHANGE: Automatic GOMAXPROCS tuning based on cgroups influences the default database connection limits. Set connection limits explicitly based on the number of CPUs in the deployment to keep previous behavior. --- cmd/server/handler.go | 9 --------- driver/factory.go | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/server/handler.go b/cmd/server/handler.go index 97400167738..873ec5844e7 100644 --- a/cmd/server/handler.go +++ b/cmd/server/handler.go @@ -29,7 +29,6 @@ import ( "github.com/rs/cors" "github.com/spf13/cobra" "github.com/urfave/negroni" - "go.uber.org/automaxprocs/maxprocs" "github.com/ory/graceful" "github.com/ory/x/healthx" @@ -191,14 +190,6 @@ func RunServeAll(slOpts []servicelocatorx.Option, dOpts []driver.OptionsModifier func setup(ctx context.Context, d driver.Registry, cmd *cobra.Command) (admin *httprouterx.RouterAdmin, public *httprouterx.RouterPublic, adminmw, publicmw *negroni.Negroni) { fmt.Println(banner(config.Version)) - if d.Config().CGroupsV1AutoMaxProcsEnabled() { - _, err := maxprocs.Set(maxprocs.Logger(d.Logger().Infof)) - - if err != nil { - d.Logger().WithError(err).Fatal("Couldn't set GOMAXPROCS") - } - } - adminmw = negroni.New() publicmw = negroni.New() diff --git a/driver/factory.go b/driver/factory.go index c7b5d30c3f4..e7d402e99ce 100644 --- a/driver/factory.go +++ b/driver/factory.go @@ -8,6 +8,7 @@ import ( "io/fs" "github.com/pkg/errors" + "go.uber.org/automaxprocs/maxprocs" "github.com/ory/hydra/v2/driver/config" "github.com/ory/hydra/v2/fositex" @@ -141,6 +142,14 @@ func New(ctx context.Context, sl *servicelocatorx.Options, opts []OptionsModifie } } + if c.CGroupsV1AutoMaxProcsEnabled() { + _, err := maxprocs.Set(maxprocs.Logger(l.Infof)) + + if err != nil { + l.WithError(err).Fatal("Couldn't set GOMAXPROCS") + } + } + r, err := NewRegistryWithoutInit(c, l) if err != nil { l.WithError(err).Error("Unable to create service registry.")