feat: default service-wide worker resource quota - #1
Merged
Conversation
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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Salvaged from the superseded
wago-org/wago#240— the only part of that PR not already inwagomain via #232.Problem
WorkerOptionsbounds each individual worker (queue depth, payload, bytes), but nothing bounds the number of live workers. A guest couldSpawnwithout end and exhaust host instances, goroutines, and foreign stacks. The coreinstance.managemaxInstancesbudget 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 viaworkers.New(workers.WithLimits(...)).Spawnclaims the quota before forking (so an over-limit spawn never allocates a managed instance) and returnsErrWorkerQuotaExceededpast the ceiling.Spawncannot exceed the ceiling during finalization.instance.managebudget.Tests
TestWorkerLimitsQuotacovers the live-worker ceiling, aggregate queue-byte ceiling (overflow-safe), slot release, and closed-service rejection.go build,go vet,gofmt, andgo test -race ./...all pass.🤖 Generated with Claude Code