birdofpreyru / react-native-fs

File system access for React Native
https://dr.pogodin.studio/docs/react-native-file-system
Other
121 stars 8 forks source link

iOS's Low Power Mode causing downloads to hang #50

Closed bitfabrikken closed 3 weeks ago

bitfabrikken commented 3 weeks ago

When "Low Power Mode" is active, downloadFile times out. Adjusting the timeouts does nothing - it never completes the download. The built in js function, fetch(), works fine.

Reproduce:

Caveats:

Reproduce code - remember to set device in Low Power Mode and unplug power. Plug in power to see it succeed with the download.

import React, { Component } from 'react';

import * as RNFS from '@dr.pogodin/react-native-fs';

export default class App extends Component {

    constructor(props) {
        super(props);

        this.reproduce();
    }

    async reproduce(){

        var opts = {
            fromUrl: "https://picsum.photos/200/300",
            toFile: RNFS.DocumentDirectoryPath+"some_file_name",
            background: false,
            discretionary: false,
            cacheable: false,
            progressInterval: 500, 
            begin: (res)=>{ console.log('download begin')},
            progress: (res)=>{ console.log('progress',res)},
            resumable: false,
            connectionTimeout: 1000,
            readTimeout: 1000,
            backgroundTimeout: 1000,
        }

        try {
            var res = await RNFS.downloadFile(opts).promise;
        } catch (err) {
            //err here will be: [Error: The request timed out.]
            return alert("Error: "+err);
        }

        alert("download successful");
    }

    render(){
        return null;
    }
}
birdofpreyru commented 3 weeks ago

Hey @bitfabrikken , do you experience it with the latest library version? As the issue sounds awful similar to the problem https://github.com/birdofpreyru/react-native-fs/issues/24#issuecomment-2138066354, fixed in v2.26.0.

bitfabrikken commented 3 weeks ago

@birdofpreyru, I just tested with 2.27.0, and it does indeed fix the problem! Thanks!