Giter Site home page Giter Site logo

Comments (15)

Ventis avatar Ventis commented on May 28, 2024

This doesn't happen with uploadFileToBlockBlob btw.

from azure-storage-js.

XiaoningLiu avatar XiaoningLiu commented on May 28, 2024

@Ventis This is a bug in RetriableReadableStream which used by blockBlobURL.download. RetriableReadableStream is referenced by the aborter timer cannot be GCed.

Before we have a fix, you can manually cancel the Aborter timer when you finish the download by:
aborter.cancelTimer().

from azure-storage-js.

ricklancee avatar ricklancee commented on May 28, 2024

We had this issue on reading that the Aborter timer would not be cleared; and since the try catch around our filesystem methods would not catch the internal errors thrown inside the Aborter's timeout we handled the timeout ourself, like so:

// example filesystem
class FileSystem {
    private aborterTimeoutSeconds: number = 60

    public async read(filePath: string): Promise<Readable> {
        const blobUrl = this.getBlobUrl(filePath)

        return new Promise<Readable>(async (resolve, reject) => {
            try {
                const { aborter, clearAborterTimer } = this.getNewAborter(reject)
                
                const downloadBlockBlobResponse = await blobUrl.download(aborter, 0)

                downloadBlockBlobResponse.readableStreamBody.on('end', () => {
                    clearAborterTimer()
                })

                // Use PassThrough to turn the original stream into Readable
                const passthrough = new PassThrough()
                downloadBlockBlobResponse.readableStreamBody.pipe(passthrough)

                resolve(passthrough)
            } catch (e) {
                reject(e)
            }
        })
    }

    private getNewAborter(reject: Function) {
        const aborter = Aborter.none

        const timer = setTimeout(() => {
            try {
                aborter.abort()
            } catch (err) {
                reject(err)
            }
        }, this.aborterTimeoutSeconds * 1000)

        const clearAborterTimer = () => {
            clearTimeout(timer)
        }

        return {
            aborter,
            clearAborterTimer,
        }
    }
}

Hope this helps someone that had a similar issue.

from azure-storage-js.

NicholasJarr avatar NicholasJarr commented on May 28, 2024

It is happenning in uploadStreamToBlockBlob too. I'm using version 10.3.0

from azure-storage-js.

NicholasJarr avatar NicholasJarr commented on May 28, 2024

aborter.cancelTimer() worked for me

from azure-storage-js.

olad32 avatar olad32 commented on May 28, 2024

Unfortunately for Typescript users cancelTimer() is a private method of Aborter class, so this "hack" is needed :
Aborter.prototype['cancelTimer'].apply(aborter);

from azure-storage-js.

XiaoningLiu avatar XiaoningLiu commented on May 28, 2024

Then we need to make cancelTimer to public

from azure-storage-js.

XiaoningLiu avatar XiaoningLiu commented on May 28, 2024

This is fixed in 10.4.0, see https://www.npmjs.com/package/@azure/storage-blob

from azure-storage-js.

highfield avatar highfield commented on May 28, 2024

@XiaoningLiu did you patch the Typescript for bringing public cancelTimer? I'm using the release 10.5, but it seems still marked as private.

from azure-storage-js.

XiaoningLiu avatar XiaoningLiu commented on May 28, 2024

@highfield We do not need to call cancelTimer as SDK fixed the issue and will not throw timeout error after download success.

from azure-storage-js.

highfield avatar highfield commented on May 28, 2024

@XiaoningLiu I wish to believe you, but I had the same problem as described above. Just after a short time the error crashed my app. That was yesterday afternoon.

Once I added the below workaround, the things seem going fine (no error after 12 hours):

        const aborter = Aborter.timeout(30 * ONE_MINUTE);
        const blockBlobURL = BlockBlobURL.fromContainerURL(this.containerURL, actualPath);
        const response = await blockBlobURL.download(aborter, 0);
        (aborter as any).cancelTimer();   // this makes the app working fine
        return response.readableStreamBody as stream.Readable;

from azure-storage-js.

XiaoningLiu avatar XiaoningLiu commented on May 28, 2024

@highfield Sorry for that. Please leverage the workaround temporiaily.
@ljian3377 Can you help quick check this issue still reproduable in latest v10 & v12 blob package versions?

from azure-storage-js.

ljian3377 avatar ljian3377 commented on May 28, 2024

@highfield Sorry for that. Please leverage the workaround temporiaily.
@ljian3377 Can you help quick check this issue still reproduable in latest v10 & v12 blob package versions?

Reproduced in 10.3 and 10.4, but not in v12.
It seems to be fixed in @azure/storage-blob version: 12.0.0. And the API has some changes. Aborter now goes in AbortController. And blockBlobURL basically is replaced by BlockBlobClient.

Code snippet used to reproduce in v12:

const downloadBlockBlobResponse: BlobDownloadResponseModel = await blockBlobClient.download(0, undefined, { abortSignal: AbortController.timeout(60000) });

setTimeout(()=>console.log("wait done"), 100000);

from azure-storage-js.

Mitsuo-Yoshida avatar Mitsuo-Yoshida commented on May 28, 2024

I know this repo is no longer maintained
But mentioning it in this issue because I found how to fix this bug here

Reproduced in 10.3 and 10.4, but not in v12.
It seems to be fixed in @azure/storage-blob version: 12.0.0. And the API has some changes. Aborter now goes in AbortController. And blockBlobURL basically is replaced by BlockBlobClient.

Code snippet used to reproduce in v12:

const downloadBlockBlobResponse: BlobDownloadResponseModel = await blockBlobClient.download(0, undefined, { abortSignal: AbortController.timeout(60000) });

setTimeout(()=>console.log("wait done"), 100000);

I reproduced this bug in @azure/storage-blob version: 12.0.0 and 12.1.2 using the code snippet provided by @ljian3377

So I used the workaround provided to fix the issue

Aborter.prototype['cancelTimer'].apply(aborter);

from azure-storage-js.

ljian3377 avatar ljian3377 commented on May 28, 2024

@Mitsuo-Yoshida
That's wierd. I still can't reproduce it. Could you please share more information of your reproduction? What envirornment?
Has the download completed when the timeout aborter aborts?

from azure-storage-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.