From 6c09be4a703eae461e237e11a80a23da5b9febb9 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 4 Nov 2026 00:46:08 +0100 Subject: [PATCH] Keep a module's report under a bounded context the client's stop does not cancel (issue 774) The test of a node coming back stops the client before the report of zsh is kept; the cancelled Put left s.applied without zsh, so leftModules never removed it (2 of 20 runs failed under -race, also at origin/main). Thorough: report() keeps under context.WithoutCancel with a 5 s bound; the same test now passes 40 of 40. Claude-Session: https://claude.ai/code/session_01JG73KG7AfSdh6FP8VrBqCn --- .../cmd/mesh-provisioner-client/client.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/mesh-provisioner-client/cmd/mesh-provisioner-client/client.go b/modules/mesh-provisioner-client/cmd/mesh-provisioner-client/client.go index 44c8e504..ee345c4a 100644 --- a/modules/mesh-provisioner-client/cmd/mesh-provisioner-client/client.go +++ b/modules/mesh-provisioner-client/cmd/mesh-provisioner-client/client.go @@ -970,7 +970,11 @@ func (c *Client) report(ctx context.Context, kvs map[string]jetstream.KeyValue, logf("[provisioner-client] the report of %s: %v", r.Module, err) return } - if _, err := kvs[AppliedBucket].Put(ctx, c.Node+"."+r.Module, body); err != nil { + // Kept under a context the client's stop does not cancel, bounded: a report made as the client stops is still kept, + // or s.applied would never name the module and a later pass would never remove it (leftModules). + keep, done := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Second) + defer done() + if _, err := kvs[AppliedBucket].Put(keep, c.Node+"."+r.Module, body); err != nil { logf("[provisioner-client] the report of %s could not be kept: %v", r.Module, err) } else { s.applied[r.Module] = true