From 3ba9ebcee2b8b43cdf2c8f8a3d810516a604b363 Mon Sep 17 00:00:00 2001 From: Alexey Alexandrov Date: Wed, 3 Feb 2021 10:31:31 -0800 Subject: [PATCH] fix(profiler): make sure retries use the most up-to-date copy of the trailer (#3660) See b/163319181 that this change fixes. Change-Id: I9d06c3cdab414ed79bd628f0abcbe6efc5cb7b09 Co-authored-by: Maggie Nolan --- profiler/profiler.go | 8 ++++---- profiler/profiler_test.go | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/profiler/profiler.go b/profiler/profiler.go index b1a82951dc9..c6f90e8b1e1 100644 --- a/profiler/profiler.go +++ b/profiler/profiler.go @@ -300,13 +300,13 @@ func abortedBackoffDuration(md grpcmd.MD) (time.Duration, error) { type retryer struct { backoff gax.Backoff - md grpcmd.MD + md *grpcmd.MD } func (r *retryer) Retry(err error) (time.Duration, bool) { st, _ := status.FromError(err) if st != nil && st.Code() == codes.Aborted { - dur, err := abortedBackoffDuration(r.md) + dur, err := abortedBackoffDuration(*r.md) if err == nil { return dur, true } @@ -328,7 +328,7 @@ func (a *agent) createProfile(ctx context.Context) *pb.Profile { } var p *pb.Profile - md := grpcmd.New(map[string]string{}) + md := grpcmd.New(nil) gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { debugLog("creating a new profile via profiler service") @@ -350,7 +350,7 @@ func (a *agent) createProfile(ctx context.Context) *pb.Profile { Max: maxBackoff, Multiplier: backoffMultiplier, }, - md: md, + md: &md, } })) diff --git a/profiler/profiler_test.go b/profiler/profiler_test.go index 097640b0cc1..00103c0f442 100644 --- a/profiler/profiler_test.go +++ b/profiler/profiler_test.go @@ -305,7 +305,7 @@ func TestRetry(t *testing.T) { Max: maxBackoff, Multiplier: backoffMultiplier, }, - md: md, + md: &md, } pause, shouldRetry := r.Retry(status.Error(codes.Aborted, "")) @@ -325,15 +325,14 @@ func TestRetry(t *testing.T) { } } - md := grpcmd.New(map[string]string{}) - + md := grpcmd.New(nil) r := &retryer{ backoff: gax.Backoff{ Initial: initialBackoff, Max: maxBackoff, Multiplier: backoffMultiplier, }, - md: md, + md: &md, } for i := 0; i < 100; i++ { pause, shouldRetry := r.Retry(errors.New(""))