From 87a5437d85313b9c5a3d667be8901d5d4dfc6d1f Mon Sep 17 00:00:00 2001 From: Damian Debkowski Date: Thu, 8 Feb 2024 23:03:22 +0000 Subject: [PATCH] backport of commit ce96a600e0f7036c948486b472bc4f61abc7be53 --- internal/bsr/internal/checksum/sha256sums.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/bsr/internal/checksum/sha256sums.go b/internal/bsr/internal/checksum/sha256sums.go index d8e2127dd6..cb0e4853c1 100644 --- a/internal/bsr/internal/checksum/sha256sums.go +++ b/internal/bsr/internal/checksum/sha256sums.go @@ -131,6 +131,8 @@ func (w *Sha256SumWriter) Write(b []byte) (int, error) { // WriteString will write the string to hash. func (w *Sha256SumWriter) WriteString(s string) (int, error) { const op = "checksum.(Sha256SumWriter).WriteString" + w.l.Lock() + defer w.l.Unlock() n, err := w.hash.Write([]byte(s)) if err != nil { return n, fmt.Errorf("%s: %w", op, err) @@ -168,6 +170,8 @@ func (w *Sha256SumWriter) WriteAndClose(b []byte) (int, error) { // and if so, then Close() is called; otherwise this is a noop func (w *Sha256SumWriter) Close() error { const op = "checksum.(Sha256SumWriter).Close" + w.l.Lock() + defer w.l.Unlock() var i interface{} = w.underlying if v, ok := i.(io.Closer); ok { if err := v.Close(); err != nil {