Merge pull request #3813 from MichaelEischer/fix-blob-saver-data-race

Fix data race in blob_saver
This commit is contained in:
Alexander Neumann 2022-07-04 08:10:01 +02:00 committed by GitHub
commit 545220803b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -45,6 +45,8 @@ func (s *BlobSaver) TriggerShutdown() {
// Save stores a blob in the repo. It checks the index and the known blobs
// before saving anything. It takes ownership of the buffer passed in.
func (s *BlobSaver) Save(ctx context.Context, t restic.BlobType, buf *Buffer) FutureBlob {
// buf might be freed once the job was submitted, thus calculate the length now
length := len(buf.Data)
ch := make(chan saveBlobResponse, 1)
select {
case s.ch <- saveBlobJob{BlobType: t, buf: buf, ch: ch}:
@ -54,7 +56,7 @@ func (s *BlobSaver) Save(ctx context.Context, t restic.BlobType, buf *Buffer) Fu
return FutureBlob{ch: ch}
}
return FutureBlob{ch: ch, length: len(buf.Data)}
return FutureBlob{ch: ch, length: length}
}
// FutureBlob is returned by SaveBlob and will return the data once it has been processed.