fix: disable scale-to-zero when process is spawned #102
+27
−6
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
ProcessSpawnstarts asynchronous processes that continue running after the HTTP request completes. The middleware only disables scale-to-zero during the HTTP request lifecycle, meaning the VM could scale down while a spawned process was still running.Solution
Explicitly call
stz.Disable()after starting the process, andstz.Enable()when the process exits. Usescontext.WithoutCancel()for the Enable call since the goroutine runs after the HTTP request returns.The
DebouncedControllerhandles reference counting, so multiple spawned processes correctly keep scale-to-zero disabled until all have exited.Changes
s.stz.Disable(ctx)aftercmd.Start()succeedss.stz.Enable(stzCtx)in the waiter goroutine when the process exitscontext.WithoutCancel(ctx)to ensure Enable works after HTTP request completesThis follows the same pattern used by
FFmpegRecorder.Start()for handling long-running processes.Note
Disables scale-to-zero after spawning a process and re-enables it on exit using a non-cancelled context; tests updated to use a Noop scale-to-zero controller.
ProcessSpawn: calls.stz.Disable(ctx)aftercmd.Start()and track success viastzDisabled.context.WithoutCancel(ctx)and re-enable vias.stz.Enable(stzCtx)only if previously disabled.stzDisabledinto waiter; add log on enable/disable errors.ApiServicewithscaletozero.NewNoopController().scaletozeroimport.Written by Cursor Bugbot for commit bdb981c. This will update automatically on new commits. Configure here.