From 4b56395369becba82c3d9ee68fd67175bd5a6919 Mon Sep 17 00:00:00 2001 From: Erik Sipsma Date: Fri, 21 Jul 2023 16:47:29 -0700 Subject: [PATCH] filesync: append rather than replace grpc md. Before this, CopyFileWriter just used metadata.NewOutgoingContext to set metadata, which results in any pre-existing metadata from the provided context to be removed. Now, it gets the current metadata and then sets its own on top of that, so any pre-existing unrelated metadata is retained. Signed-off-by: Erik Sipsma --- session/filesync/filesync.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/session/filesync/filesync.go b/session/filesync/filesync.go index 712469a9b779..026fac52f9b2 100644 --- a/session/filesync/filesync.go +++ b/session/filesync/filesync.go @@ -11,6 +11,7 @@ import ( "unicode" "github.com/moby/buildkit/session" + "github.com/moby/buildkit/util/bklog" "github.com/pkg/errors" "github.com/tonistiigi/fsutil" fstypes "github.com/tonistiigi/fsutil/types" @@ -317,9 +318,16 @@ func CopyFileWriter(ctx context.Context, md map[string]string, c session.Caller) client := NewFileSendClient(c.Conn()) - opts := make(map[string][]string, len(md)) + opts, ok := metadata.FromOutgoingContext(ctx) + if !ok { + opts = make(map[string][]string, len(md)) + } for k, v := range md { - opts[keyExporterMetaPrefix+k] = []string{v} + k := keyExporterMetaPrefix + k + if existingVal, ok := opts[k]; ok { + bklog.G(ctx).Warnf("overwriting grpc metadata key %q from value %+v to %+v", k, existingVal, v) + } + opts[k] = []string{v} } ctx = metadata.NewOutgoingContext(ctx, opts)