question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FileSystem.downloadAsync/FileSystem.createDownloadResumable.downloadAsync doesn't close requests on Android/Snack

See original GitHub issue

Environment

Expo CLI 2.3.12 environment info: System: OS: Linux 4.15 Ubuntu 18.04.1 LTS (Bionic Beaver) Shell: 4.4.19 - /bin/bash Binaries: Node: 10.10.0 - ~/.nvm/versions/node/v10.10.0/bin/node npm: 6.4.1 - ~/.nvm/versions/node/v10.10.0/bin/npm npmPackages: expo: ^31.0.2 => 31.0.2 react: 16.5.0 => 16.5.0 react-native: https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz => 0.57.1 npmGlobalPackages: expo-cli: 2.3.12

Steps to Reproduce

On Android and in Snack, requests made using FileSystem.downloadAsync aren’t closed when the download is complete and hang around. If the remote server then blocks requests because too many are open, the app red screens in native code, or crashes with no information (only observed on Android).

  1. Setup to download multiple files from a remote server, can be multiple simultaneous or sequential downloads
  2. Watch the requests build on the remote server (e.g., by using netstat -nputwc
  3. Wait until the requests eventually close (Snack?) or kill expo (Android).

Expected Behavior

Requests closed when the download is complete.

Actual Behavior

On Android (OnePlus 6) multiple requests were left open in the TIME_WAIT status (netstat), on iPhone (iPhone 6S) the requests are closed properly (no more than a few over the maximum parallel downloads observed). image Image is of output when run on physical Android device.

Reproducible Demo

The demo uses 100 text files with random characters in, split into 5 queues. On iPhone running from expo the number of requests at once will hover around 6-8, but on Android the number of requests is excessive (see above screenshot). https://snack.expo.io/@innershed/YW5kcm

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

6reactions
JeffBobbocommented, Jul 4, 2019

I implemented a version with the same function signature but just used axios and Buffer. Still relies on Expo.FileSystem for writing to file. This has only been tested with images and audio files, though, as that was my use case.

import axios from 'axios';

import {FileSystem} from 'expo';

var md5 = require('md5');
var Buffer = require('buffer/').Buffer;

async function downloadAsync(uri, fileUri, options = {'md5': false}) {
    let response = await axios.get(uri, {responseType: 'arraybuffer'});
    await FileSystem.writeAsStringAsync(
        fileUri,
        Buffer.from(response.data, 'binary').toString('base64'),
        {encoding: FileSystem.EncodingTypes.Base64}
    );

    let ret = {
        uri: fileUri,
        status: response.status,
        headers: response.headers,
    };
    if (options.md5)
        ret.md5 = md5(response.data);
    return ret;
}

export {downloadAsync};
1reaction
zetxycommented, Jan 5, 2019

I am experiencing the same issue. Application on my android phone / emulator crashes when downloading larger amount of files.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FileSystem - Expo Documentation
Create a DownloadResumable object which can start, pause, and resume a download of contents at a remote URI to a file in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found