hostedctl: bound every provider call; cancel the reaper at shutdown
C2 + B2-2 (R27): New wraps the runner and auditor so Launch gets 60 s and every other call and the network audit 30 s, derived from the caller's context. Refresh's recovery Suspend and Resume now get the caller's context; only store writes use a detached copy. After the drain period serve cancels requests and the reaper together, then joins both, so a Stop waiting on a lock a stalled reaper Get holds cannot hang shutdown.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 files changed,
+345
−21
cmd/equipo-hosted-controller/main.go+10 −7cmd/equipo-hosted-controller/main_test.go+77 −0docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md+18 −0internal/hostedctl/bounded.go+63 −0internal/hostedctl/controller.go+2 −1internal/hostedctl/launch.go+4 −5internal/hostedctl/refresh.go+3 −2internal/hostedctl/refresh_test.go+156 −0internal/hostedctl/resume.go+12 −6
diff --git a/cmd/equipo-hosted-controller/main.go b/cmd/equipo-hosted-controller/main.go| index 96b75e3f..2cce51d3 100644 |
| --- a/cmd/equipo-hosted-controller/main.go |
| +++ b/cmd/equipo-hosted-controller/main.go |
| @@ -157,12 +157,12 @@ func newMetricsServer(h http.Handler) *http.Server { |
| // serve runs the reaper loop and both servers until ctx ends (a signal) or |
| // a server fails. Then, in order: the servers stop accepting and get drain |
| -// to finish their requests; any request still running has its context |
| -// cancelled, and serve waits for every handler to return; only then is the |
| -// reaper, which has a lifetime of its own, stopped and joined. The caller |
| -// closes the store after serve returns, so no request or reaper pass ever |
| -// runs on a closed store. A handler that ignores its cancelled context holds |
| -// shutdown until it returns. |
| +// to finish their requests; the requests still running and the reaper, |
| +// which has a lifetime of its own, are both cancelled; and serve waits for |
| +// every handler and the reaper to return. The caller closes the store after |
| +// serve returns, so no request or reaper pass ever runs on a closed store. |
| +// Every provider call is bounded (hostedctl.ProviderCallTimeout), so a |
| +// handler or pass that ignores its cancelled context still returns. |
| func serve(ctx context.Context, c *hostedctl.Controller, apiSrv *http.Server, apiLn net.Listener, |
| metricsSrv *http.Server, metricsLn net.Listener, drain time.Duration) error { |
| reqCtx, cancelRequests := context.WithCancel(context.Background()) |
| @@ -192,9 +192,12 @@ func serve(ctx context.Context, c *hostedctl.Controller, apiSrv *http.Server, ap |
| log.Printf("equipo-hosted-controller: requests still running after %v; cancelling them: %v", drain, err) |
| } |
| cancel() |
| + // Both at once, then join both (ruling R27): a request may be waiting |
| + // for an attempt lock a reaper pass holds across a provider call, and |
| + // only the reaper's cancellation ends that call. |
| cancelRequests() |
| - active.closeAndWait() |
| stopReaper() |
| + active.closeAndWait() |
| if err := <-reaperDone; err != nil { |
| log.Printf("equipo-hosted-controller: last reaper pass: %v", err) |
| } |
diff --git a/cmd/equipo-hosted-controller/main_test.go b/cmd/equipo-hosted-controller/main_test.go| index aedca95c..e7426349 100644 |
| --- a/cmd/equipo-hosted-controller/main_test.go |
| +++ b/cmd/equipo-hosted-controller/main_test.go |
| @@ -205,6 +205,83 @@ func TestProviderNamespace(t *testing.T) { |
| } |
| } |
| +// getBlock wraps the Fake. Once armed, Get closes entered and waits for its |
| +// context to end, as a stalled provider read that honours cancellation. |
| +type getBlock struct { |
| + isolatedjob.Runner |
| + armed atomic.Bool |
| + once sync.Once |
| + entered chan struct{} |
| +} |
| + |
| +func (g *getBlock) Get(ctx context.Context, ref isolatedjob.Ref) (isolatedjob.Job, error) { |
| + if !g.armed.Load() { |
| + return g.Runner.Get(ctx, ref) |
| + } |
| + g.once.Do(func() { close(g.entered) }) |
| + <-ctx.Done() |
| + return isolatedjob.Job{}, ctx.Err() |
| +} |
| + |
| +// TestShutdownCancelsReaperWithRequests: a reaper pass is stuck in a Get |
| +// that ends only with its context, holding the attempt's lock, and a Stop |
| +// request for that attempt waits for the lock. On a signal serve must |
| +// cancel the reaper along with the requests before joining either, or the |
| +// Stop handler, and with it shutdown, waits on the lock (C2, R27). |
| +func TestShutdownCancelsReaperWithRequests(t *testing.T) { |
| + t.Parallel() |
| + gb := &getBlock{entered: make(chan struct{})} |
| + tc := newTestCtl(t, func(f *isolatedjob.Fake) isolatedjob.Runner { gb.Runner = f; return gb }) |
| + if _, err := tc.c.Launch(context.Background(), instID, hostedwire.VerifyKey{Role: hostedwire.RoleInstance}, |
| + hostedctl.LaunchRequest{AttemptID: "a1", TaskID: "t1", Account: "acct", Image: testDigest, |
| + Size: isolatedjob.SizeSmall, MaxLifetime: 2 * time.Hour, InstanceCode: "code-1"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + gb.armed.Store(true) |
| + var once sync.Once |
| + entered := make(chan struct{}) |
| + api := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + once.Do(func() { close(entered) }) |
| + tc.api.ServeHTTP(w, r) |
| + }) |
| + cert, client := testTLS(t) |
| + apiLn, metricsLn := listen(t), listen(t) |
| + ctx, signal := context.WithCancel(context.Background()) |
| + defer signal() |
| + served := make(chan error, 1) |
| + go func() { |
| + served <- serve(ctx, tc.c, newAPIServer(api, cert), apiLn, newMetricsServer(hostedctl.NewMetrics().Handler(tc.c)), |
| + metricsLn, 100*time.Millisecond) |
| + }() |
| + select { |
| + case <-gb.entered: |
| + case <-time.After(10 * time.Second): |
| + t.Fatal("the reaper's Get never reached the provider") |
| + } |
| + body, _ := json.Marshal(hostedwire.StopRequest{Reason: "done"}) |
| + req, err := http.NewRequest(http.MethodPost, "https://"+apiLn.Addr().String()+"/v1/jobs/a1/stop", bytes.NewReader(body)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + tc.sign(t, req, body) |
| + go func() { |
| + if resp, err := client.Do(req); err == nil { |
| + _ = resp.Body.Close() |
| + } |
| + }() |
| + select { |
| + case <-entered: |
| + case <-time.After(10 * time.Second): |
| + t.Fatal("the Stop request never reached its handler") |
| + } |
| + signal() |
| + select { |
| + case <-served: |
| + case <-time.After(10 * time.Second): |
| + t.Fatal("serve did not return within 10 s of the signal") |
| + } |
| +} |
| + |
| // blockingRunner holds every Launch until its context ends, then takes a |
| // while more to return, like a provider call settling. |
| type blockingRunner struct { |
diff --git a/docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md| index a4f6c2f8..74a0d0e0 100644 |
| --- a/docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md |
| +++ b/docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md |
| @@ -966,3 +966,21 @@ Findings from the final whole-branch review (final-A, B1, B2, C), fixed under ru |
| | --- | --- | --- | --- | |
| | Refuse empty egress in `awsjob.Config.check` again | `go test ./internal/isolatedjob/awsjob -run 'TestNew$\|TestAuditNetwork$' -count=1` | `runner_test.go:208: New(no egress) = isolatedjob: invalid request: awsjob config: no egress destinations, want nil` and `network_test.go:267: New(no egress) = ...` | yes, passes | |
| | Accept a non-empty egress in the command | `go test ./cmd/equipo-hosted-controller -run 'TestConfigRefusesMissingListenOrKeys$' -count=1` | `config_test.go:114: egress in slice 1a: config loaded, want a refusal` | yes, passes | |
| + |
| +### C2 + B2-2: bounded provider calls, cancellable recovery calls, shutdown order (R27) |
| + |
| +- `New` wraps the runner and auditor (`bounded.go`): Launch gets `ProviderLaunchTimeout` (60 s, |
| + moved out of `dispatch`), every other call and the network audit `ProviderCallTimeout` (30 s), |
| + each derived from the caller's context. |
| +- `refreshOne` passes its own context to `mirrorLive`, which uses it for the Suspend and Resume it |
| + sends again and a detached copy only for store writes and audit rows. |
| +- `serve` cancels the requests and the reaper together after the drain period, then joins both; |
| + the caller closes the store after. |
| + |
| +| Mutation | Command | Observed failure | Restored | |
| +| --- | --- | --- | --- | |
| +| Old shutdown order (join handlers before cancelling the reaper) | `go test ./cmd/equipo-hosted-controller -run 'TestShutdownCancelsReaperWithRequests$' -count=1` | `main_test.go:281: serve did not return within 10 s of the signal` | yes, passes | |
| +| No deadline on Get in `boundedRunner` | `go test ./internal/hostedctl -run 'TestProviderCallsBounded$' -count=1` | `refresh_test.go:783: unbounded provider calls: [get: deadline set false, ... get: ...]` | yes, passes | |
| +| No deadline on the network audit | same | `refresh_test.go:783: unbounded provider calls: [audit: deadline set false, ... audit: ...]` | yes, passes | |
| +| `refreshOne` hands `mirrorLive` the detached context | `go test ./internal/hostedctl -run 'TestRefreshRecoveryCallsCancel$' -count=1` | `refresh_test.go:855: Refresh still in its suspend call 5 s after its context was cancelled` | yes, passes | |
| +| Only the resume re-send gets the detached context | same | `refresh_test.go:855: Refresh still in its resume call 5 s after its context was cancelled` | yes, passes | |
diff --git a/internal/hostedctl/bounded.go b/internal/hostedctl/bounded.go| new file mode 100644 |
| index 00000000..2aafdb8d |
| --- /dev/null |
| +++ b/internal/hostedctl/bounded.go |
| @@ -0,0 +1,63 @@ |
| +package hostedctl |
| + |
| +import ( |
| + "context" |
| + |
| + "amadan.net/oficina/equipo/internal/isolatedjob" |
| +) |
| + |
| +// boundedRunner is the runner the controller calls through. Each provider |
| +// call gets a deadline derived from the caller's context (ruling R27): |
| +// ProviderLaunchTimeout for Launch (R21) and ProviderCallTimeout for the |
| +// rest, retries included. A caller's earlier deadline, or its cancellation, |
| +// still ends the call first. Results are recorded by the caller on a |
| +// context of its own. |
| +type boundedRunner struct{ r isolatedjob.Runner } |
| + |
| +func (b boundedRunner) Launch(ctx context.Context, s isolatedjob.LaunchSpec) (isolatedjob.Ref, error) { |
| + ctx, cancel := context.WithTimeout(ctx, ProviderLaunchTimeout) |
| + defer cancel() |
| + return b.r.Launch(ctx, s) |
| +} |
| + |
| +func (b boundedRunner) Get(ctx context.Context, ref isolatedjob.Ref) (isolatedjob.Job, error) { |
| + ctx, cancel := context.WithTimeout(ctx, ProviderCallTimeout) |
| + defer cancel() |
| + return b.r.Get(ctx, ref) |
| +} |
| + |
| +func (b boundedRunner) Suspend(ctx context.Context, ref isolatedjob.Ref) error { |
| + ctx, cancel := context.WithTimeout(ctx, ProviderCallTimeout) |
| + defer cancel() |
| + return b.r.Suspend(ctx, ref) |
| +} |
| + |
| +func (b boundedRunner) Resume(ctx context.Context, ref isolatedjob.Ref) error { |
| + ctx, cancel := context.WithTimeout(ctx, ProviderCallTimeout) |
| + defer cancel() |
| + return b.r.Resume(ctx, ref) |
| +} |
| + |
| +func (b boundedRunner) Stop(ctx context.Context, ref isolatedjob.Ref, reason string) error { |
| + ctx, cancel := context.WithTimeout(ctx, ProviderCallTimeout) |
| + defer cancel() |
| + return b.r.Stop(ctx, ref, reason) |
| +} |
| + |
| +func (b boundedRunner) List(ctx context.Context) ([]isolatedjob.Job, error) { |
| + ctx, cancel := context.WithTimeout(ctx, ProviderCallTimeout) |
| + defer cancel() |
| + return b.r.List(ctx) |
| +} |
| + |
| +func (b boundedRunner) Limits() isolatedjob.Limits { return b.r.Limits() } |
| + |
| +// boundedAuditor gives each network audit, every read in it included, |
| +// ProviderCallTimeout (R27). |
| +type boundedAuditor struct{ a isolatedjob.NetworkAuditor } |
| + |
| +func (b boundedAuditor) AuditNetwork(ctx context.Context) (isolatedjob.NetworkAudit, error) { |
| + ctx, cancel := context.WithTimeout(ctx, ProviderCallTimeout) |
| + defer cancel() |
| + return b.a.AuditNetwork(ctx) |
| +} |
diff --git a/internal/hostedctl/controller.go b/internal/hostedctl/controller.go| index fefbf893..0afc1a50 100644 |
| --- a/internal/hostedctl/controller.go |
| +++ b/internal/hostedctl/controller.go |
| @@ -101,7 +101,8 @@ func New(cfg Config, d Deps) (*Controller, error) { |
| } |
| cfg.Images = maps.Clone(cfg.Images) |
| cfg.Egress = slices.Clone(cfg.Egress) |
| - return &Controller{cfg: cfg, store: d.Store, runner: d.Runner, auditor: d.Auditor, alerter: d.Alerter}, nil |
| + return &Controller{cfg: cfg, store: d.Store, runner: boundedRunner{d.Runner}, auditor: boundedAuditor{d.Auditor}, |
| + alerter: d.Alerter}, nil |
| } |
| // isNil reports whether v is nil or an interface holding a nil pointer, map, |
diff --git a/internal/hostedctl/launch.go b/internal/hostedctl/launch.go| index dbd45a21..83a64bee 100644 |
| --- a/internal/hostedctl/launch.go |
| +++ b/internal/hostedctl/launch.go |
| @@ -490,11 +490,10 @@ func (c *Controller) dispatch(ctx context.Context, actor hostedwire.KeyID, attem |
| } else if gate := c.creatable(spec.Image, now); gate != nil { |
| return view, gate, nil |
| } |
| - // R21: bounded, so no launch call this process makes can outlive the |
| - // Ref-less proof fence (ReflessProofDelay) that starts at its dispatch. |
| - lctx, cancel := context.WithTimeout(ctx, ProviderLaunchTimeout) |
| - ref, perr := c.runner.Launch(lctx, spec) |
| - cancel() |
| + // R21: c.runner bounds the call by ProviderLaunchTimeout, so no launch |
| + // call this process makes can outlive the Ref-less proof fence |
| + // (ReflessProofDelay) that starts at its dispatch. |
| + ref, perr := c.runner.Launch(ctx, spec) |
| // Record the answer even if the caller has gone: a VM may now exist. |
| view, err = c.settle(context.WithoutCancel(ctx), actor, attempt, ref, perr, replay) |
| return view, nil, err |
diff --git a/internal/hostedctl/refresh.go b/internal/hostedctl/refresh.go| index 279d3fc2..b4233c4d 100644 |
| --- a/internal/hostedctl/refresh.go |
| +++ b/internal/hostedctl/refresh.go |
| @@ -209,8 +209,9 @@ func (c *Controller) refreshOne(ctx context.Context, attempt string) error { |
| c.rebased.readOK(attempt) |
| if job.State.Live() { |
| // First, so a live sighting clears any first not-found even when |
| - // the restart handling below stops the job. |
| - if err := c.mirrorLive(rec, j, job.State); err != nil { |
| + // the restart handling below stops the job. It gets ctx, not rec: |
| + // its provider calls must end when the caller does (R27). |
| + if err := c.mirrorLive(ctx, j, job.State); err != nil { |
| return err |
| } |
| } |
diff --git a/internal/hostedctl/refresh_test.go b/internal/hostedctl/refresh_test.go| index 55eb2846..1ba5484b 100644 |
| --- a/internal/hostedctl/refresh_test.go |
| +++ b/internal/hostedctl/refresh_test.go |
| @@ -700,3 +700,159 @@ func TestProviderLaunchTimeout(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// deadlineAll wraps the fake provider and records, for every call other |
| +// than Launch, whether its context had a deadline at most |
| +// ProviderCallTimeout away. |
| +type deadlineAll struct { |
| + *isolatedjob.Fake |
| + mu sync.Mutex |
| + bad []string |
| + ops map[string]int |
| +} |
| + |
| +func (d *deadlineAll) note(ctx context.Context, op string) { |
| + dl, ok := ctx.Deadline() |
| + d.mu.Lock() |
| + defer d.mu.Unlock() |
| + d.ops[op]++ |
| + if left := time.Until(dl); !ok || left <= 0 || left > ProviderCallTimeout { |
| + d.bad = append(d.bad, fmt.Sprintf("%s: deadline set %v, %v left", op, ok, left)) |
| + } |
| +} |
| + |
| +func (d *deadlineAll) Get(ctx context.Context, r isolatedjob.Ref) (isolatedjob.Job, error) { |
| + d.note(ctx, "get") |
| + return d.Fake.Get(ctx, r) |
| +} |
| + |
| +func (d *deadlineAll) List(ctx context.Context) ([]isolatedjob.Job, error) { |
| + d.note(ctx, "list") |
| + return d.Fake.List(ctx) |
| +} |
| + |
| +func (d *deadlineAll) Stop(ctx context.Context, r isolatedjob.Ref, why string) error { |
| + d.note(ctx, "stop") |
| + return d.Fake.Stop(ctx, r, why) |
| +} |
| + |
| +func (d *deadlineAll) Suspend(ctx context.Context, r isolatedjob.Ref) error { |
| + d.note(ctx, "suspend") |
| + return d.Fake.Suspend(ctx, r) |
| +} |
| + |
| +func (d *deadlineAll) Resume(ctx context.Context, r isolatedjob.Ref) error { |
| + d.note(ctx, "resume") |
| + return d.Fake.Resume(ctx, r) |
| +} |
| + |
| +func (d *deadlineAll) AuditNetwork(ctx context.Context) (isolatedjob.NetworkAudit, error) { |
| + d.note(ctx, "audit") |
| + return d.Fake.AuditNetwork(ctx) |
| +} |
| + |
| +// TestProviderCallsBounded: every provider call other than Launch, the |
| +// network audit included, carries a deadline at most ProviderCallTimeout |
| +// away, though the caller's context has none (ruling R27). |
| +func TestProviderCallsBounded(t *testing.T) { |
| + t.Parallel() |
| + e := newLaunchEnv(t) |
| + d := &deadlineAll{Fake: e.fake, ops: map[string]int{}} |
| + c, err := New(e.cfg, Deps{Store: e.store, Runner: d, Auditor: d, Alerter: &recordingAlerter{}}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + e.c = c |
| + e.audit() |
| + e.launchWith("att-1", 2*time.Hour) |
| + e.fake.Tick() |
| + e.reap() |
| + e.suspendJob() |
| + if _, err := e.resume("op-1"); !errors.Is(err, ErrResumePending) { |
| + t.Fatalf("Resume = %v, want ErrResumePending", err) |
| + } |
| + if _, err := e.c.Stop(e.ctx, "inst-1", instKey, "att-1", "done"); !errors.Is(err, ErrStopPending) { |
| + t.Fatalf("Stop = %v, want ErrStopPending", err) |
| + } |
| + for _, op := range []string{"get", "list", "stop", "suspend", "resume", "audit"} { |
| + if d.ops[op] == 0 { |
| + t.Fatalf("no %s call made; calls %v", op, d.ops) |
| + } |
| + } |
| + if len(d.bad) > 0 { |
| + t.Fatalf("unbounded provider calls: %v", d.bad) |
| + } |
| +} |
| + |
| +// ctxBlock wraps the fake provider. A call to op closes entered and then |
| +// waits for its context to end. |
| +type ctxBlock struct { |
| + *isolatedjob.Fake |
| + op isolatedjob.Op |
| + entered chan struct{} |
| +} |
| + |
| +func (b *ctxBlock) block(ctx context.Context, op isolatedjob.Op) (bool, error) { |
| + if op != b.op { |
| + return false, nil |
| + } |
| + close(b.entered) |
| + <-ctx.Done() |
| + return true, ctx.Err() |
| +} |
| + |
| +func (b *ctxBlock) Suspend(ctx context.Context, r isolatedjob.Ref) error { |
| + if held, err := b.block(ctx, isolatedjob.OpSuspend); held { |
| + return err |
| + } |
| + return b.Fake.Suspend(ctx, r) |
| +} |
| + |
| +func (b *ctxBlock) Resume(ctx context.Context, r isolatedjob.Ref) error { |
| + if held, err := b.block(ctx, isolatedjob.OpResume); held { |
| + return err |
| + } |
| + return b.Fake.Resume(ctx, r) |
| +} |
| + |
| +// TestRefreshRecoveryCallsCancel: the suspend and the resume Refresh sends |
| +// again for a pause or resume it is finishing end when Refresh's context |
| +// is cancelled; they are not detached from it (B2-2, R27). |
| +func TestRefreshRecoveryCallsCancel(t *testing.T) { |
| + t.Parallel() |
| + for _, op := range []isolatedjob.Op{isolatedjob.OpSuspend, isolatedjob.OpResume} { |
| + e := runningJob(t) |
| + if op == isolatedjob.OpSuspend { // suspending, the VM still running |
| + g := e.drain() |
| + e.ack(g) |
| + e.fake.Inject(isolatedjob.OpSuspend, isolatedjob.FaultThrottle) |
| + if err := e.c.Suspend(e.ctx, "inst-1", instKey, "att-1", g); err == nil { |
| + t.Fatal("throttled Suspend = nil, want its error") |
| + } |
| + } else { // resuming, the VM still suspended |
| + e.suspendJob() |
| + e.fake.Inject(isolatedjob.OpResume, isolatedjob.FaultThrottle) |
| + if _, err := e.resume("op-1"); !errors.Is(err, ErrResumePending) { |
| + t.Fatalf("throttled Resume = %v, want ErrResumePending", err) |
| + } |
| + } |
| + b := &ctxBlock{Fake: e.fake, op: op, entered: make(chan struct{})} |
| + e.run = b |
| + e.newController() |
| + ctx, cancel := context.WithCancel(e.ctx) |
| + done := make(chan error, 1) |
| + go func() { done <- e.c.Refresh(ctx) }() |
| + select { |
| + case <-b.entered: |
| + case <-time.After(5 * time.Second): |
| + cancel() |
| + t.Fatalf("Refresh never sent the %s again", op) |
| + } |
| + cancel() |
| + select { |
| + case <-done: |
| + case <-time.After(5 * time.Second): |
| + t.Fatalf("Refresh still in its %s call 5 s after its context was cancelled", op) |
| + } |
| + } |
| +} |
diff --git a/internal/hostedctl/resume.go b/internal/hostedctl/resume.go| index 935f73e2..6a637334 100644 |
| --- a/internal/hostedctl/resume.go |
| +++ b/internal/hostedctl/resume.go |
| @@ -444,7 +444,11 @@ func pauseState(state string) bool { |
| // pending resume stays pending for the next pass; a terminal VM gets proof |
| // from refreshOne, which fails its pending resume in the same transaction |
| // (writeProof). |
| -func (c *Controller) mirrorLive(ctx context.Context, j jobRow, st isolatedjob.State) error { |
| +// |
| +// Provider calls get call, the caller's context, so they end when it does; |
| +// store writes use a detached copy, so what Get saw is recorded even then. |
| +func (c *Controller) mirrorLive(call context.Context, j jobRow, st isolatedjob.State) error { |
| + ctx := context.WithoutCancel(call) |
| if !pauseState(j.state) && !j.stopRequested.Valid { |
| return c.mirrorState(ctx, j.attempt, st) |
| } |
| @@ -476,7 +480,7 @@ func (c *Controller) mirrorLive(ctx context.Context, j jobRow, st isolatedjob.St |
| return appendAudit(tx, a) |
| case p.state == JobSuspending && st == isolatedjob.StateRunning && !pastStop(&p, now): |
| next = func() error { |
| - _, aerr := c.sendSuspend(ctx, "", &p, actionSuspendResent) // a failed call is audited and sent again next pass |
| + _, aerr := c.sendSuspend(call, "", &p, actionSuspendResent) // a failed call is audited and sent again next pass |
| return aerr |
| } |
| return nil |
| @@ -495,7 +499,7 @@ func (c *Controller) mirrorLive(ctx context.Context, j jobRow, st isolatedjob.St |
| case st == isolatedjob.StateRunning: |
| return commitResume(ctx, tx, &p, op, "", now) |
| case st == isolatedjob.StateSuspended: |
| - next = func() error { return c.resendResume(ctx, &p, op) } |
| + next = func() error { return c.resendResume(call, &p, op) } |
| } |
| return nil |
| }) |
| @@ -515,9 +519,11 @@ func (c *Controller) resendResume(ctx context.Context, j *pauseJob, op resumeOp) |
| if pastStop(j, c.store.Clock().Now()) { |
| return nil |
| } |
| - if perr := c.runner.Resume(ctx, isolatedjob.Ref(j.ref.String)); perr != nil { |
| - return c.auditPause(ctx, "", j, actionResumeCallFailed, |
| + perr := c.runner.Resume(ctx, isolatedjob.Ref(j.ref.String)) |
| + rec := context.WithoutCancel(ctx) |
| + if perr != nil { |
| + return c.auditPause(rec, "", j, actionResumeCallFailed, |
| fmt.Sprintf("refresh: operation %s: provider resume call failed; the operation stays pending", op.id)) |
| } |
| - return c.auditPause(ctx, "", j, actionResumeResent, fmt.Sprintf("refresh: operation %s pending; the VM still reports suspended, resume sent again", op.id)) |
| + return c.auditPause(rec, "", j, actionResumeResent, fmt.Sprintf("refresh: operation %s pending; the VM still reports suspended, resume sent again", op.id)) |
| } |