Skip to content

Commit

Permalink
fix(profiler): make sure retries use the most up-to-date copy of the …
Browse files Browse the repository at this point in the history
…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 authored Feb 3, 2021
1 parent 1aea7c8 commit 3ba9ebc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
8 changes: 4 additions & 4 deletions profiler/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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")
Expand All @@ -350,7 +350,7 @@ func (a *agent) createProfile(ctx context.Context) *pb.Profile {
Max: maxBackoff,
Multiplier: backoffMultiplier,
},
md: md,
md: &md,
}
}))

Expand Down
7 changes: 3 additions & 4 deletions profiler/profiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""))
Expand All @@ -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(""))
Expand Down

0 comments on commit 3ba9ebc

Please sign in to comment.