From 8d97901e8f3da50daeb003998170fb1ee20c2005 Mon Sep 17 00:00:00 2001 From: Jens Reimann Date: Tue, 12 Oct 2021 12:44:59 +0200 Subject: [PATCH] fix: fix thread synchronization issue #6245 --- internal/ingress/controller/template/template.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index e5da5b9936..63a71ff1e8 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -63,6 +63,9 @@ const ( // Writer is the interface to render a template type Writer interface { + // Write renders the template. + // NOTE: Implementors must ensure that the content of the returned slice is not modified by the implementation + // after the return of this function. Write(conf config.TemplateConfig) ([]byte, error) } @@ -202,7 +205,12 @@ func (t *Template) Write(conf config.TemplateConfig) ([]byte, error) { return nil, err } - return outCmdBuf.Bytes(), nil + // make a copy to ensure that we are no longer modifying the content of the buffer + out := outCmdBuf.Bytes() + res := make([]byte, len(out)) + copy(res, out) + + return res, nil } var (