tobydeh / nativescript-download-progress

Download large files in Nativescript with progress events
Apache License 2.0
11 stars 16 forks source link

Downloader crashes on multiple downloads on Android #18

Closed wendt88 closed 3 years ago

wendt88 commented 4 years ago

tns info:

√ Getting NativeScript components versions information...
√ Component nativescript has 6.5.0 version and is up to date.
√ Component tns-core-modules has 6.5.1 version and is up to date.
√ Component tns-android has 6.5.0 version and is up to date.
√ Component tns-ios has 6.5.0 version and is up to date.

code example:

async download () {
    try {
        let folder = fs.knownFolders.documents().getFolder('test'),
            fileUrls = new Array(10).fill('https://miro.medium.com/max/1200/1*mk1-6aYaf_Bes1E3Imhc0A.jpeg');
        await folder.clear();
        for (let i in fileUrls) {
            const download = new DownloadProgress();
            download.addProgressCallback(progress => {
                console.log(`Progress file ${i}:`, progress);
            })
            await download.downloadFile(
                fileUrls[i],
                fs.path.join(folder.path, i + '.jpeg')
            )
                .then(f => {
                    console.log(`Success file ${i}:`, f);
                })
                .catch(e => {
                    console.log(`Error file ${i}:`, e);
                })
        }
    }
    catch (e) {
        console.error(e);
    }
    console.log('Finish!');
}

calling the download method, the app crashes after the 2nd file without error, or the app gets frozen. when I debug it and keep the breakpoint after every file for a few seconds, it works sometimes.

wendt88 commented 4 years ago

it works fine without this line

tobydeh commented 4 years ago

I have run the code snippet you provided and cannot reproduce the error. Please create an example project demonstrating the issue.

wendt88 commented 4 years ago

it occures not every time (on my emulator or even phone ca in 80% of the cases)

tobydeh commented 3 years ago

I ran the test again today and I'm still unable to reproduce the issue. Are you able to setup an example repo?

wendt88 commented 3 years ago

here you can find an example just clone and run tns run android inside the app click the 'download'-button

tobydeh commented 3 years ago

Thanks, I cloned your demo repository and ran the example without any issues.

What version of the android sdk do you have installed?

wendt88 commented 3 years ago

with the 29: tns run android --compileSdk 29 I added a log inside the app and made a video: download-progress-demo

tobydeh commented 3 years ago

I managed to cause the issue once and have not been able to replicate it again.

Could you please set supressCallJSMethodExceptions: true to prevent the application crashing and add some logging using the trace module so we can try to find the error.

wendt88 commented 3 years ago

I added "discardUncaughtJsExceptions": true to my app/package.json, like here right? But get no error. In debug mode, at least the com.tns.ErrorReportActivity-activity should open, but the app crashes without error. it seems more like a out of memory or something like this, not properly a js/code error.

tobydeh commented 3 years ago

Please can you try nativescript-download-progress@next

wendt88 commented 3 years ago

Please can you try nativescript-download-progress@next

now it crashes on every 3-5th run. before it crashed at 90%, so it is much better, but not safe enough for my use case :/

wendt88 commented 3 years ago

now i debuged with Android studio and before he started to download the last file (before it crashed), i got the followed error inside the logcat:

NativeAlloc concurrent copying GC freed 3625(323KB) AllocSpace objects, 4(80KB) LOS objects, 49% free, 2924KB/5848KB, paused 5.726ms total 75.313ms

is it helpful?

tobydeh commented 3 years ago

Could you please try restructuring your code, move the DownloadProgress instantiation outside of the for loop..

await folder.clear();
const download = new DownloadProgress();
for (let i in fileUrls) {
download.addProgressCallback(progress => {})
wendt88 commented 3 years ago

now i was able to download 100 files in a row multiple time without crash, thank you very much! i saw, that i tried already to move it outside the loop in my main repo, without success, so 1.4.2-rc1 seems to fix this issue