Skip to content
Permalink
Browse files
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 <nolanmar@google.com>
  • Loading branch information
aalexand and nolanmar511 committed Feb 3, 2021
1 parent 1aea7c8 commit 3ba9ebcee2b8b43cdf2c8f8a3d810516a604b363
Showing with 7 additions and 8 deletions.
  1. +4 −4 profiler/profiler.go
  2. +3 −4 profiler/profiler_test.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,
}
}))

@@ -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(""))

0 comments on commit 3ba9ebc

Please sign in to comment.