Repository navigation
fix(controller): keep removals moving while a runner starts - #99
Merged
Merged
Conversation
The reconciler started a runner with a synchronous call, so a scale set removed nothing until the provider's StartInstance returned. A start can wait in the provider for host capacity that only a removal returns, and only the reconciler claims removals. With two macOS Tart scale sets on one host this could stop both for good. The default process-wide limit is the sum of max-runners, which is above the host's two VM permits. Each scale set could hold a finished runner it never removed and a start that waited for a permit. The reconciler now reserves the runner's name and lease, then runs the start in its own goroutine, as it already does for removals. Drain and Shutdown wait for that goroutine before they take their snapshots. Starts stay one at a time per scale set. Providers have never been asked to start two instances at once, and the start-failure backoff counts consecutive failures.
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.
Problem
Each scale set has one reconciler goroutine. It hands removals to their own goroutines, but it started a runner with a synchronous call. Until the provider's
StartInstancereturned, that scale set removed nothing.A start can take minutes, and it can wait in the provider for host capacity. The Tart provider waits for one of the host's two macOS VM permits, or for a warm VM. A permit comes back only when a VM is removed, and only the reconciler claims removals.
With two macOS Tart scale sets on one host, both can stop for good:
max-runners, which is 4 here, so each gets a lease and entersStartInstance, where it waits for a permit.When only one scale set is scaling up, it does not deadlock, but it stalls until the other scale set's job ends.
The comment on
acquireCapacitydescribes the same hazard for the capacity lease and avoids it by abandoning the wait on a reconcile signal. The provider's wait had no such way out.Fix
The reconciler now reserves the runner's name and lease, then runs the start in its own goroutine, as it already does for removals. The instance state already reserved a runner before provider I/O and already handled a completion or a drain that races a start, so no new state was needed beyond "a start is in flight".
reserveStartrecords the runner as provisioning, so the next reconcile pass counts it.provisionis the rest of the formerstartInstanceWithLease. It runs in the goroutine and signals the reconciler when it ends.DrainandShutdownwait for that goroutine before they take their snapshots. A start adds observer goroutines, so it is waited for before them.Starts stay one at a time per scale set. Providers have never been asked to start two instances at once, and the start-failure backoff counts consecutive failures. Starting several runners in parallel is a separate change.
The providers are unchanged, and there is no new configuration.
Tests
internal/controller/start_in_flight_test.gouses a provider that holds a start until it gets a permit. The tests run undertesting/synctest, so they do not depend on timing.TestRemovalDoesNotWaitForStartInFlightTestScaleSetsSharingHostLimitDoNotDeadlockTestOneStartInFlightPerScaleSetgo test ./... -race,go vet ./...andgolangci-lint run ./...pass.Verified on a Tart host
Run on an Apple silicon host with tart 2.40.1: two controllers, each with a real Tart provider, sharing the host's two macOS VM permits and a process-wide limit of 4. The guests ran a stand-in for the runner, and jobs were simulated by calling the controller's job handlers, so no GitHub registration was involved. The harness is build-tagged and not part of this PR.
Each scale set started one VM and was given a job, then asked for a second runner, then had its job finish.
mainNot verified
DrainandShutdownwaiting for the start goroutine. The existing drain and shutdown tests pass under the race detector.