From 802aa2bdf9c1bef55abc37736b55b86547e267f9 Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Tue, 22 Mar 2022 10:32:44 -0700 Subject: [PATCH 1/2] [md_copy] metadata: copy slices in FromContext() functions --- metadata/metadata.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/metadata/metadata.go b/metadata/metadata.go index 3604c7819fd..def39f39fb7 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -188,7 +188,7 @@ func FromIncomingContext(ctx context.Context) (MD, bool) { // map, and there's no guarantee that the MD attached to the context is // created using our helper functions. key := strings.ToLower(k) - out[key] = v + out[key] = append(out[key], v...) } return out, true } @@ -226,7 +226,7 @@ func FromOutgoingContext(ctx context.Context) (MD, bool) { // map, and there's no guarantee that the MD attached to the context is // created using our helper functions. key := strings.ToLower(k) - out[key] = v + out[key] = append(out[key], v...) } for _, added := range raw.added { if len(added)%2 == 1 { From 5342e536a8e339183f76d5d919f4e1866b14ea5e Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Tue, 22 Mar 2022 13:56:05 -0700 Subject: [PATCH 2/2] [md_copy] c0 --- metadata/metadata.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/metadata/metadata.go b/metadata/metadata.go index def39f39fb7..8e0f6abe89d 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -188,7 +188,9 @@ func FromIncomingContext(ctx context.Context) (MD, bool) { // map, and there's no guarantee that the MD attached to the context is // created using our helper functions. key := strings.ToLower(k) - out[key] = append(out[key], v...) + s := make([]string, len(v)) + copy(s, v) + out[key] = s } return out, true } @@ -226,7 +228,9 @@ func FromOutgoingContext(ctx context.Context) (MD, bool) { // map, and there's no guarantee that the MD attached to the context is // created using our helper functions. key := strings.ToLower(k) - out[key] = append(out[key], v...) + s := make([]string, len(v)) + copy(s, v) + out[key] = s } for _, added := range raw.added { if len(added)%2 == 1 {