rn-fetch-blob icon indicating copy to clipboard operation
rn-fetch-blob copied to clipboard

App crash on Android with Error: canceled due to java.lang.IllegalStateException: cannot make a new request because the previous response is still open: please call response.close()

Open reeinohio opened this issue 2 years ago • 10 comments

I recently upgraded my app's react native library from 0.63 to 0.67.4 and I am now targeting,compiling for Android 12 (SDK 31) from Android 11 (SDK 30). I am using rn-fetch-blob v0.12.0 to fetch a PDF. After the upgrade I am now getting this error when trying to fetch:

canceled due to java.lang.IllegalStateException: cannot make a new request because the previous response is still open: please call response.close()

Is there additional setup/config changes to support SDK 31 (Android 12)? This https://github.com/joltup/rn-fetch-blob/issues/478 seems to report the same issue but it is for Android 9. My app was working when it was compiled for and targeting android 11.

Any help or suggestions will be highly appreciated.

  • Library versions and config versions rn-fetch-blob 0.12.0 react-native 0.67.4
  • Android config:
  1. gradle-wrapper.properties distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip

  2. build.gradle

  buildscript {
      ext {
          buildToolsVersion = "31.0.0"
          minSdkVersion = 21
          compileSdkVersion = 31
          targetSdkVersion = 31
          ...
      }
      ext.kotlinVersion  = '1.6.21'
      repositories {
          google()
          mavenCentral()
          ...
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:7.0.4'
          ...
      }
  }
  • Sample code
import RNFetchBlob from "rn-fetch-blob";
import { Platform, PermissionsAndroid } from "react-native";

...
let allPermissionsGranted = false;
if (Platform.OS === "android") {
   const granted = await PermissionsAndroid.requestMultiple([
            PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
            PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
        ]);
   allPermissionsGranted =
            granted["android.permission.READ_EXTERNAL_STORAGE"] === "granted" && granted["android.permission.WRITE_EXTERNAL_STORAGE"] === "granted";
}
try {
  const res = await RNFetchBlob.config({
                trusty: true,
                fileCache: false,
                path: directory + "/" + filename,
            }).fetch("GET", docUrl, headers);
  const status = res.info().status;
  if (status === 200) {
      if (Platform.OS === "ios") {
          RNFetchBlob.ios.openDocument(res.path());
       } else {
           if (allPermissionsGranted) {
               const android = RNFetchBlob.android;
               android.actionViewIntent(res.path(), mimetype);
           }
         }
      }
    } else {
       console.log("Error fetching file");
       throw new Error("...")
    }
} catch (e) {
    console.error(e);
}

Note: The try catch above is not catching the exception. The app crashes and closes when it gets the error.

reeinohio avatar Jun 22 '22 23:06 reeinohio

The reported issue don't seem to occur when I updated to rn-fetch-blob 0.13.0-beta.1. Will a final version of this be releasing soon?

reeinohio avatar Jun 23 '22 17:06 reeinohio

Nope it won't. Just switch to https://www.npmjs.com/package/react-native-blob-util

RonRadtke avatar Jul 02 '22 18:07 RonRadtke

Same +1

KuiGoan avatar Aug 05 '22 04:08 KuiGoan

+1

dishantjaykasodhan-kiwi avatar Aug 21 '22 14:08 dishantjaykasodhan-kiwi

This repo is dead...

RonRadtke avatar Aug 22 '22 13:08 RonRadtke

Any update on this? Facing this issue.

christopher-18 avatar Oct 14 '22 15:10 christopher-18

@christopher-18 yep, migrate to https://www.npmjs.com/package/react-native-blob-util

RonRadtke avatar Oct 14 '22 19:10 RonRadtke

Solution https://stackoverflow.com/a/77329785/11762907 android/media/ Folder name should be the package name

shivo-ham avatar Oct 23 '23 05:10 shivo-ham

The reported issue don't seem to occur when I updated to rn-fetch-blob 0.13.0-beta.1. Will a final version of this be releasing soon?

The issue reproduces for me on 0.13.0-beta.1 still :'(

raymondjacobson avatar Feb 16 '24 02:02 raymondjacobson

wrapping the config with addAndroidDownloads solved this for me:

const configfb = {
      addAndroidDownloads: {
        useDownloadManager: true,
        notification: true,
        mediaScannable: true,
        title: fileName,
        path: `${dirToSave}/${fileName}`,
      },
    };

saumya66 avatar Jun 21 '24 08:06 saumya66