azure-sdk-for-go icon indicating copy to clipboard operation
azure-sdk-for-go copied to clipboard

Azblob: DownloadBlobToWriterAt gets context cancelled

Open eccles opened this issue 2 years ago • 8 comments

Bug Report

import azStorageBlob "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" 0.3.0 go version go1.17.7 linux/amd64

Attempts to download a blob with the following call:

func (rr *ReaderResponse) DownloadToWriter(ctx context.Context, w io.Writer) error {
        return rr.BlobClient.DownloadBlobToWriterAt(
                ctx,   /// context.BackGround() in most cases
                0,
                rr.CountToEnd,    /// standard MS constant
                newWriterAt(w),   /// convrets io.Writer to io.WriterAt with zero offset
                azStorageBlob.HighLevelDownloadFromBlobOptions{},
        )
}

when calling using a http.ResponseWriter as the io.Writer results in a context cancelled error most of the time. About 1 in 4 attempts are successful.

The error is "copied to out with errors: context canceled"

Expected: No context cancelled error and successful download

Similar code using the older azure-storage-blob-go repo worked. This was discovered whilst moving across to azure-sdk-for-go.

eccles avatar Apr 20 '22 16:04 eccles

Ctx has the following value:

ontext: context.Background.WithValue(type *http.contextKey, val <not Stringer>).WithValue(type *http.contextKey, val 10.244.11.160:8000).WithCancel.WithCancel.WithValue(type metadata.mdIncomingKey, val <not Stringer>).WithValue(type mux.contextKey, val <not Stringer>).WithValue(type mux.contextKey, val <not Stringer>).WithCancel

eccles avatar Apr 20 '22 16:04 eccles

Note that various ctx args were tried such as context.Background() to no avail

eccles avatar Apr 20 '22 16:04 eccles

Thank you for your feedback. This has been routed to the support team for assistance.

msftbot[bot] avatar Apr 20 '22 18:04 msftbot[bot]

I have reworked the code to get the Body and feed that as a Reader to io.Copy. This still gets the context canceleld error

     resp.BlobClient = azp.containerClient.NewBlobClient(identity)
        resp.CountToEnd = int64(azStorageBlob.CountToEnd)
        get, err := resp.BlobClient.Download(
                ctx,
                &azStorageBlob.DownloadBlobOptions{
                        BlobAccessConditions: &resp.blobAccessConditions,
                        Count:                &resp.CountToEnd,
                },
        )
        if err != nil && err == io.EOF { // nolint
                logger.Sugar.Infof("cannot get blob body: %v", err)
                return nil, ErrorFromError(err)
        }
        resp.Reader = get.Body(&azStorageBlob.RetryReaderOptions{})
       _, err = io.Copy(w, resp.Reader)
        if err != nil {
                logger.Sugar.Infof("copied to out with errors: %v", err)
        }

eccles avatar Apr 22 '22 08:04 eccles

@eccles We are looking into it and get back to you for any additional information.

SaurabhSharma-MSFT avatar Apr 22 '22 18:04 SaurabhSharma-MSFT

thank you for your attention - this is not urgent but will require a fix if we are to move to the new azure-sdk as recommended by yourselves.

eccles avatar Apr 26 '22 09:04 eccles

This might have been due to an issue in azcore which has since been fixed. https://github.com/Azure/azure-sdk-for-go/pull/17797

We've just released an updated version [email protected] that contains this (and other fixes). Note that we've refactored the public surface area. However, we feel that it makes navigating the package much easier. Can you please try it and report back?

jhendrixMSFT avatar Sep 29 '22 22:09 jhendrixMSFT

Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

msftbot[bot] avatar Oct 07 '22 02:10 msftbot[bot]