Detach runner launch from request timeout
Some checks are pending
Build Rust / Cargo Test (push) Waiting to run
Build Site / Next.js Build (push) Waiting to run

This commit is contained in:
Conrad Kramer 2026-03-18 23:07:57 -07:00
parent 6300c661ff
commit b9fb30c18c

View file

@ -94,6 +94,17 @@ type RunnerHandle struct {
Name string `json:"name"` Name string `json:"name"`
} }
func launchContext(ttl time.Duration) (context.Context, context.CancelFunc) {
if ttl <= 0 {
return context.WithTimeout(context.Background(), 2*time.Hour)
}
// Provisioning can legitimately take several minutes before the runner starts
// processing the actual Forgejo job. Keep the launch context independent from
// the caller's HTTP timeout so autoscaler/webhook requests don't kill active
// bootstraps mid-flight.
return context.WithTimeout(context.Background(), ttl+30*time.Minute)
}
func (s *Service) Dispatch(ctx context.Context, req DispatchRequest) (DispatchResponse, error) { func (s *Service) Dispatch(ctx context.Context, req DispatchRequest) (DispatchResponse, error) {
count := req.Count count := req.Count
if count <= 0 { if count <= 0 {
@ -134,7 +145,10 @@ func (s *Service) Dispatch(ctx context.Context, req DispatchRequest) (DispatchRe
return fmt.Errorf("fetching registration token: %w", err) return fmt.Errorf("fetching registration token: %w", err)
} }
name, err := s.dispatcher.LaunchRunner(egCtx, nsc.LaunchRequest{ launchCtx, cancel := launchContext(ttl)
defer cancel()
name, err := s.dispatcher.LaunchRunner(launchCtx, nsc.LaunchRequest{
Token: token, Token: token,
InstanceURL: s.instanceURL, InstanceURL: s.instanceURL,
Labels: labels, Labels: labels,