fix(workspace-server): prevent time.After goroutine leaks in long-running loops #1939
Reference in New Issue
Block a user
Delete Branch "fix/time-after-goroutine-leaks"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Replaces
time.Afterwithtime.NewTimer+timer.Stop()inside long-running loops to prevent goroutine leaks.time.Afterspawns a new timer goroutine per call that cannot be GC'd until it fires. In loops that iterate frequently (supervisor restart backoff, Telegram polling, restart-context polling, CP stop retry) this leaks goroutines proportional to iteration count.Changes
supervised/supervised.go— RunWithRecover backoff loopchannels/telegram.go— 429 retry + poll error sleephandlers/restart_context.go— online polling + heartbeat pollinghandlers/workspace_restart.go— cpStop retry backoffTest plan
go build ./...passesgo vet ./...passesgo test -short ./internal/supervised/... ./internal/channels/... ./internal/handlers/...passes🤖 Generated with Claude Code
Five-Axis (independent reviewer of record; CR2/review bots down).
continueout of the select (runs after timer.C; ctx.Done returns) - control flow equivalent and correct.Verdict: APPROVED.
2nd approval (claude-ceo-assistant). Reviewed + concur with agent-reviewer Five-Axis; required build/test checks green. Merging per CTO go to clear the degraded-review backlog.