From 5e78b45ef3c47e04e76b82b25560a2544e05816b Mon Sep 17 00:00:00 2001 From: whywaita Date: Wed, 10 Jul 2024 12:34:45 +0900 Subject: [PATCH] Set deadline timeout for blocking loop of delete --- pkg/runner/runner_delete.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/runner/runner_delete.go b/pkg/runner/runner_delete.go index 195c130..1ef337d 100644 --- a/pkg/runner/runner_delete.go +++ b/pkg/runner/runner_delete.go @@ -30,6 +30,8 @@ type Runner struct { var ( // ConcurrencyDeleting is value of concurrency ConcurrencyDeleting atomic.Int64 + // DeletingTimeout is timeout of deleting runner + DeletingTimeout = 3 * time.Minute ) func (m *Manager) do(ctx context.Context) error { @@ -104,12 +106,15 @@ func (m *Manager) removeRunners(ctx context.Context, t datastore.Target) error { ConcurrencyDeleting.Add(1) eg.Go(func() error { + cctx, cancel := context.WithTimeout(ctx, DeletingTimeout) + defer cancel() + defer func() { sem.Release(1) ConcurrencyDeleting.Add(-1) }() - if err := m.removeRunner(ctx, t, runner, ghRunners); err != nil { + if err := m.removeRunner(cctx, t, runner, ghRunners); err != nil { logger.Logf(false, "failed to delete runner: %+v", err) } return nil