Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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() #795

Open
reeinohio opened this issue Jun 22, 2022 · 10 comments

Comments

@reeinohio
Copy link

reeinohio commented Jun 22, 2022

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 #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
Copy link
Author

reeinohio commented Jun 23, 2022

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?

@RonRadtke
Copy link

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

@KuiGoan
Copy link

KuiGoan commented Aug 5, 2022

Same +1

@dishantjaykasodhan-kiwi

+1

@RonRadtke
Copy link

This repo is dead...

@christopher-18
Copy link

Any update on this? Facing this issue.

@RonRadtke
Copy link

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

@shivo-ham
Copy link

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

@raymondjacobson
Copy link

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 :'(

@saumya66
Copy link

wrapping the config with addAndroidDownloads solved this for me:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants