ory/hydra · error

could not set GOMAXPROCS: %w

Error message

could not set GOMAXPROCS: %w

What it means

driver/registry_sql.go Init wraps a maxprocs.Set failure with "could not set GOMAXPROCS: %w". When cgroups-based auto GOMAXPROCS is enabled (CGroupsV1AutoMaxProcsEnabled), the driver uses uber-go/automaxprocs to align GOMAXPROCS with the container CPU quota; failure here aborts initialization.

Source

Thrown at driver/registry_sql.go:196

// of RegistrySQL.initialPing.
func defaultInitialPing(ctx context.Context, l *logrusx.Logger, p *sql.BasePersister) error {
	return errors.WithStack(resilience.Retry(l, 5*time.Second, 5*time.Minute, func() error {
		return p.Ping(ctx)
	}))
}

func (m *RegistrySQL) Init(
	ctx context.Context,
	skipNetworkInit bool,
	migrate bool,
	extraMigrations []fs.FS,
	goMigrations []popx.Migration,
) error {
	if m.basePersister == nil {
		if m.Config().CGroupsV1AutoMaxProcsEnabled() {
			_, err := maxprocs.Set(maxprocs.Logger(m.Logger().Infof))
			if err != nil {
				return fmt.Errorf("could not set GOMAXPROCS: %w", err)
			}
		}

		// new db connection
		pool, idlePool, connMaxLifetime, connMaxIdleTime, cleanedDSN := sqlcon.ParseConnectionOptions(
			m.l, m.Config().DSN(),
		)

		opts := &pop.ConnectionDetails{
			URL:             sqlcon.FinalizeDSN(m.l, cleanedDSN),
			IdlePool:        idlePool,
			ConnMaxLifetime: connMaxLifetime,
			ConnMaxIdleTime: connMaxIdleTime,
			Pool:            pool,
			TracerProvider:  m.Tracer(ctx).Provider(),
			Unsafe:          m.Config().DbIgnoreUnknownTableColumns(),
		}

View on GitHub (pinned to 4174065ffb)

Solutions

  1. Disable the auto max procs setting (e.g. set the cgroups v1 auto max procs config flag to false) and set GOMAXPROCS explicitly via env
  2. Mount cgroup v1 or check the underlying wrapped error for the exact read failure
  3. Upgrade to a version that supports cgroup v2 detection
  4. Run with privileged/sysfs access if in a restricted sandbox

Example fix

# before
# dsn: ...  (cgroups auto max procs enabled)
# after
GOMAXPROCS=2 hydra serve all  # or disable cgroups_v1_auto_max_procs in config
Defensive patterns

Strategy: fallback

Validate before calling

if _, err := os.Stat("/sys/fs/cgroup"); err != nil {
    log.Println("cgroup fs unavailable: disable auto max procs")
}

Try / catch

if err != nil {
    log.Warnf("maxprocs: %v - continuing with default GOMAXPROCS", err)
}

Prevention

When it happens

Trigger: Starting Hydra with cgroups auto-max-procs enabled in an environment where /sys/fs/cgroup (cgroup v1) files are unreadable or the mount is missing.

Common situations: Running in Docker/Kubernetes with cgroup v2 while the feature assumes v1, restricted container runtimes (gVisor, some CI sandboxes) hiding /proc/self/cgroup, or read-only /sys mounts.

Related errors


AI-assisted analysis of ory/hydra@4174065ffb (2026-09-03). Data as JSON: /api/errors/11c57c1f1dcb6e95. Report an issue: GitHub.