goharbor/harbor · error

resources is negative for resource(s)

Error message

resources is negative for resource(s): %s

What it means

Guard inside reserveResources' quota update closure: after adding the requested resources to usage, the resulting used value would be negative, indicating quota accounting corruption (over-rollback). Raised via the quota controller's update path called by Request.

Solutions

  1. Investigate prior rollback operations that may have decremented usage too far
  2. Recalculate quota usage for the affected quota via refresh/usage reconciliation
  3. Check for concurrent update races on the same quota record
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/controller/quota/controller.go:504 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of goharbor/harbor@7b2fd08cc5 (2026-08-16). Data as JSON: /api/errors/c1d2016e9a391676. Report an issue: GitHub.

Appendix: source

Thrown at src/controller/quota/controller.go:504

func reserveResources(resources types.ResourceList) func(hardLimits, used types.ResourceList) (types.ResourceList, error) {
	return func(hardLimits, used types.ResourceList) (types.ResourceList, error) {
		newUsed := types.Add(used, resources)

		if err := quota.IsSafe(hardLimits, used, newUsed, false); err != nil {
			return nil, errors.DeniedError(err).WithMessagef("Quota exceeded when processing the request of %v", err)
		}

		return newUsed, nil
	}
}

func rollbackResources(resources types.ResourceList) func(hardLimits, used types.ResourceList) (types.ResourceList, error) {
	return func(_, used types.ResourceList) (types.ResourceList, error) {
		newUsed := types.Subtract(used, resources)
		// ensure that new used is never negative
		if negativeUsed := types.IsNegative(newUsed); len(negativeUsed) > 0 {
			return nil, fmt.Errorf("resources is negative for resource(s): %s", quota.PrettyPrintResourceNames(negativeUsed))
		}

		return newUsed, nil
	}
}

func refreshResources(calculateUsage func() (types.ResourceList, error), ignoreLimitation bool) func(hardLimits, used types.ResourceList) (types.ResourceList, error) {
	return func(hardLimits, used types.ResourceList) (types.ResourceList, error) {
		newUsed, err := calculateUsage()
		if err != nil {
			return nil, err
		}

		// ensure that new used is never negative
		if negativeUsed := types.IsNegative(newUsed); len(negativeUsed) > 0 {
			return nil, fmt.Errorf("quota usage is negative for resource(s): %s", quota.PrettyPrintResourceNames(negativeUsed))
		}

View on GitHub (pinned to 7b2fd08cc5)