Skip to content

Commit

Permalink
Resolving Concurrency Issues (#275)
Browse files Browse the repository at this point in the history
* Resolving concurrency issues

* Fixing concurrency test

* Minor changes
  • Loading branch information
siminsavani-msft authored Jul 1, 2021
1 parent 0aff822 commit 0946547
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions azblob/chunkwriting.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func copyFromReader(ctx context.Context, from io.Reader, to blockWriter, o Uploa
}
// If the error is not EOF, then we have a problem.
if err != nil && !errors.Is(err, io.EOF) {
cp.wg.Wait()
return nil, err
}

Expand Down
28 changes: 28 additions & 0 deletions azblob/zt_highlevel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,31 @@ func (s *aztestsSuite) TestDoBatchTransferWithError(c *chk.C) {
mmf.isClosed = true
time.Sleep(time.Second * 5)
}

func (s *aztestsSuite) Test_CopyFromReader(c *chk.C) {
ctx := context.Background()
p, err := createSrcFile(_1MiB * 12)
if err != nil {
c.Assert(err, chk.IsNil)
}

defer os.Remove(p)

from, err := os.Open(p)
if err != nil {
c.Assert(err, chk.IsNil)
}

br := newFakeBlockWriter()
defer br.cleanup()

br.errOnBlock = 1
transferManager, err := NewStaticBuffer(_1MiB, 1)
if err != nil {
panic(err)
}
defer transferManager.Close()
_, err = copyFromReader(ctx, from, br, UploadStreamToBlockBlobOptions{TransferManager: transferManager})
c.Assert(err, chk.NotNil)
c.Assert(err.Error(), chk.Equals, "write error: multiple Read calls return no data or error")
}

0 comments on commit 0946547

Please sign in to comment.