Skip to content

Commit

Permalink
fix: fix thread synchronization issue kubernetes#6245 (kubernetes#7800)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron authored and rchshld committed May 17, 2023
1 parent 6afa069 commit 973cd34
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/ingress/controller/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 973cd34

Please sign in to comment.