Skip to content

Commit 6846021

Browse files
committed
fix: preserve deadline in singleflight context to bound RPC lifetime
context.WithoutCancel detaches cancellation but also drops the deadline. Re-apply the original deadline so gRPC calls inside singleflight still have a bounded lifetime under server outage conditions. Addresses cubic-dev-ai review feedback. Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
1 parent ea1ea0a commit 6846021

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

pkg/policies/group_loader.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,14 @@ func (c *ChainloopGroupLoader) Load(ctx context.Context, attachment *v1.PolicyGr
137137
}
138138

139139
providerRef := ProviderParts(ref)
140+
// Detach from caller's cancellation (so one goroutine's cancel doesn't
141+
// kill the shared singleflight call) but preserve a bounded deadline.
140142
sfCtx := context.WithoutCancel(ctx)
143+
if deadline, ok := ctx.Deadline(); ok {
144+
var cancel context.CancelFunc
145+
sfCtx, cancel = context.WithDeadline(sfCtx, deadline)
146+
defer cancel()
147+
}
141148

142149
resp, err := c.Client.GetPolicyGroup(sfCtx, &pb.AttestationServiceGetPolicyGroupRequest{
143150
Provider: providerRef.Provider,

pkg/policies/loader.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,14 @@ func (c *ChainloopLoader) Load(ctx context.Context, attachment *v1.PolicyAttachm
197197
}
198198

199199
providerRef := ProviderParts(ref)
200+
// Detach from caller's cancellation (so one goroutine's cancel doesn't
201+
// kill the shared singleflight call) but preserve a bounded deadline.
200202
sfCtx := context.WithoutCancel(ctx)
203+
if deadline, ok := ctx.Deadline(); ok {
204+
var cancel context.CancelFunc
205+
sfCtx, cancel = context.WithDeadline(sfCtx, deadline)
206+
defer cancel()
207+
}
201208

202209
resp, err := c.Client.GetPolicy(sfCtx, &pb.AttestationServiceGetPolicyRequest{
203210
Provider: providerRef.Provider,

0 commit comments

Comments
 (0)