Commit 1349e74
authored
fix: disable scale-to-zero when process is spawned (#102)
## Problem
`ProcessSpawn` starts 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, and
`stz.Enable()` when the process exits. Uses `context.WithoutCancel()`
for the Enable call since the goroutine runs after the HTTP request
returns.
The `DebouncedController` handles reference counting, so multiple
spawned processes correctly keep scale-to-zero disabled until all have
exited.
## Changes
- Add `s.stz.Disable(ctx)` after `cmd.Start()` succeeds
- Add `s.stz.Enable(stzCtx)` in the waiter goroutine when the process
exits
- Use `context.WithoutCancel(ctx)` to ensure Enable works after HTTP
request completes
This follows the same pattern used by `FFmpegRecorder.Start()` for
handling long-running processes.
<!-- CURSOR_SUMMARY -->
---
> [!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.
>
> - **Backend (Process management)**
> - `ProcessSpawn`: call `s.stz.Disable(ctx)` after `cmd.Start()` and
track success via `stzDisabled`.
> - Waiter goroutine: use `context.WithoutCancel(ctx)` and re-enable via
`s.stz.Enable(stzCtx)` only if previously disabled.
> - Minor: pass `stzDisabled` into waiter; add log on enable/disable
errors.
> - **Tests**
> - Update spawn/stream/stdin/kill tests to initialize `ApiService` with
`scaletozero.NewNoopController()`.
> - Add `scaletozero` import.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
bdb981c. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent bd49aff commit 1349e74
2 files changed
+27
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
243 | 252 | | |
244 | 253 | | |
245 | 254 | | |
| |||
294 | 303 | | |
295 | 304 | | |
296 | 305 | | |
297 | | - | |
298 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
299 | 310 | | |
300 | 311 | | |
301 | 312 | | |
| |||
310 | 321 | | |
311 | 322 | | |
312 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
313 | 333 | | |
314 | 334 | | |
315 | 335 | | |
| |||
325 | 345 | | |
326 | 346 | | |
327 | 347 | | |
328 | | - | |
| 348 | + | |
329 | 349 | | |
330 | 350 | | |
331 | 351 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | | - | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
114 | | - | |
| 115 | + | |
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
| |||
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
153 | | - | |
| 154 | + | |
154 | 155 | | |
155 | 156 | | |
156 | 157 | | |
| |||
0 commit comments