Skip to content

feat: default service-wide worker resource quota - #1

Merged
Jairus (JairusSW) merged 1 commit into
mainfrom
add-worker-service-quota
Jul 11, 2026
Merged

feat: default service-wide worker resource quota#1
Jairus (JairusSW) merged 1 commit into
mainfrom
add-worker-service-quota

Conversation

@JairusSW

Copy link
Copy Markdown
Member

Salvaged from the superseded wago-org/wago#240 — the only part of that PR not already in wago main via #232.

Problem

WorkerOptions bounds each individual worker (queue depth, payload, bytes), but nothing bounds the number of live workers. A guest could Spawn without end and exhaust host instances, goroutines, and foreign stacks. The core instance.manage maxInstances budget only caps this when the host explicitly grants it a budget; a plain grant leaves workers unbounded.

Change

Add WorkerLimits{MaxLiveWorkers, MaxQueueBytes} — a service-wide aggregate cap with sane defaults (64 live workers, 64 MiB summed queue reservation), applied automatically or overridden via workers.New(workers.WithLimits(...)).

  • Spawn claims the quota before forking (so an over-limit spawn never allocates a managed instance) and returns ErrWorkerQuotaExceeded past the ceiling.
  • The reservation is held until the worker goroutine finishes (after instance close + all exit observers), so a concurrent Spawn cannot exceed the ceiling during finalization.
  • Complements — does not replace — the core instance.manage budget.

Tests

TestWorkerLimitsQuota covers the live-worker ceiling, aggregate queue-byte ceiling (overflow-safe), slot release, and closed-service rejection. go build, go vet, gofmt, and go test -race ./... all pass.

🤖 Generated with Claude Code

Per-worker WorkerOptions bounded each worker's queue, but nothing bounded the
number of live workers, so a guest could spawn without end and exhaust host
instances, goroutines, and foreign stacks. The core instance.manage maxInstances
budget only caps this when the host grants it explicitly.

Add WorkerLimits{MaxLiveWorkers, MaxQueueBytes} with sane defaults (64 workers,
64 MiB aggregate) applied via New(WithLimits(...)) or automatically. Spawn claims
the quota before forking and reports ErrWorkerQuotaExceeded when over the ceiling;
the reservation is held until the worker's goroutine finishes so a concurrent
Spawn cannot exceed the ceiling during finalization. This complements — not
replaces — the core instance.manage budget.

Salvaged from the superseded PR wago-org/wago#240; the rest of that PR is already
in main via #232.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@JairusSW
Jairus (JairusSW) merged commit 94c790d into main Jul 11, 2026
1 check passed
Jairus (JairusSW) added a commit that referenced this pull request Jul 11, 2026
feat: default service-wide worker resource quota
Signed-off-by: JairusSW <jairus@impart.security>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant