react-native-windows icon indicating copy to clipboard operation
react-native-windows copied to clipboard

avmoroz/react-native-fs crashing on downloadFile

Open cjhines opened this issue 3 years ago • 8 comments
trafficstars

Problem Description

I'm getting the following error while calling downloadFile with avmoroz/react-native-fs. Anyone encountered it or can offer some advice? I also tried wwimmo/react-native-fs with no luck.

RNFS.dll!winrt::impl::consume_Windows_Foundation_IPropertyValue<winrt::Windows::Foundation::IReference<unsigned __int64>>::Type() Line 190	C++
RNFS.dll!RNFSManager::ProcessDownloadRequestAsync$_ResumeCoro$1() Line 954	C++
[External Code]	
RNFS.dll!winrt::impl::resume_apartment(const winrt::impl::resume_apartment_context & context, std::experimental::coroutine_handle<void> handle) Line 8289	C++
RNFS.dll!winrt::impl::disconnect_aware_handler::Complete() Line 3148	C++
RNFS.dll!winrt::impl::disconnect_aware_handler::operator()() Line 3139	C++
RNFS.dll!<lambda_7b3a35664967a00a906a66b76e011559>::operator()<winrt::Windows::Foundation::IAsyncOperationWithProgress<winrt::Windows::Web::Http::HttpResponseMessage,winrt::Windows::Web::Http::HttpProgress> const &,enum winrt::Windows::Foundation::AsyncStatus>(const winrt::Windows::Foundation::IAsyncOperationWithProgress<winrt::Windows::Web::Http::HttpResponseMessage,winrt::Windows::Web::Http::HttpProgress> & __formal, winrt::Windows::Foundation::AsyncStatus operation_status) Line 3168	C++
RNFS.dll!winrt::impl::delegate<winrt::Windows::Foundation::AsyncOperationWithProgressCompletedHandler<winrt::Windows::Web::Http::HttpResponseMessage,winrt::Windows::Web::Http::HttpProgress>,<lambda_7b3a35664967a00a906a66b76e011559>>::Invoke(void * asyncInfo, int asyncStatus) Line 860	C++
[External Code]
Screenshot 2022-09-05 at 17 53 50

Steps To Reproduce

const download = await FileSystem.downloadFile({
  fromUrl,
  toFile: destinationPath,
  headers: {
    Authorization: `Bearer ${Config.API_KEY}`,
  },
});

Expected Results

No response

CLI version

8.0.6

Environment

System:
    OS: Windows 10 10.0.22000
    CPU: (4) x64 Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz
    Memory: 9.58 GB / 15.99 GB
  Binaries:
    Node: 16.15.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
    npm: 8.11.0 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK:
      AllowDevelopmentWithoutDevLicense: Enabled
      AllowAllTrustedApps: Enabled
      Versions: 10.0.18362.0, 10.0.19041.0
  IDEs:
    Android Studio: Not Found
    Visual Studio: 16.11.32602.291 (Visual Studio Community 2019)
  Languages:
    Java: Not Found
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.0.0 => 18.0.0
    react-native: 0.69.5 => 0.69.5
    react-native-windows: 0.69.6 => 0.69.6
  npmGlobalPackages:
    *react-native*: Not Found

Target Platform Version

No response

Target Device(s)

No response

Visual Studio Version

Visual Studio 2019

Build Configuration

No response

Snack, code example, screenshot, or link to a repository

No response

cjhines avatar Sep 06 '22 11:09 cjhines

Can you provide the native callstack for that AV in RNFS.dll?

chrisglein avatar Sep 08 '22 18:09 chrisglein

Can you provide the native callstack for that AV in RNFS.dll?

Thanks for the response.

What's "AV" in this context? Apologies, still fairly new to navigating VS for RNW

cjhines avatar Sep 09 '22 15:09 cjhines

What's interesting is the first file of my array downloads successfully:

Destination: C:\Users\admin\AppData\Local\Packages\7dc6f71d-85ee\LocalState/7f7c30c2.jpg

Source: [redacted-base-url]/api/modules/file/objects/7f7c30c2/media/medium

and the second file crashes:

Destination C:\Users\admin\AppData\Local\Packages\7dc6f71d-85ee\LocalState/fff3c435.png

Source [redacted-base-url]/api/modules/file/objects/fff3c435/media/medium

cjhines avatar Sep 09 '22 17:09 cjhines

What's "AV" in this context? Apologies, still fairly new to navigating VS for RNW

AV = Access Violation. The crash stack that is referenced in your screenshot above from the thrown exception. Can you attach the debugger in a way that gets that crash information?

chrisglein avatar Sep 12 '22 18:09 chrisglein

@vmoroz FYI

chrisglein avatar Sep 12 '22 18:09 chrisglein

@chrisglein

Value of below is 0x0000005316ffbd64 {Empty (0)}:

Screenshot 2022-09-13 at 18 09 33

cjhines avatar Sep 13 '22 16:09 cjhines

@chrisglein

Seems that whenever something is compared to PropertyType::UInt64 the crash occurs.

Removing this code block:

RN::JSValueObject values = RN::JSValueObject{
	{ "jobId", jobId },
	{ "statusCode", (int)response.StatusCode() },
	{ "contentLength", contentLength.Type() == PropertyType::UInt64 ? RN::JSValue(contentLength.Value()) : RN::JSValue{nullptr} },
	{ "headers", std::move(headersMap) },
};

results in the crash occurring later, here:

auto contentLengthForProgress = contentLength.Type() == PropertyType::UInt64 ? contentLength.Value() : -1;

If I declare and breakpoint the value of contentLength.Type() the value is -858993460 Screenshot 2022-09-14 at 09 48 57

Removing this second comparison stops the crash, but breaks the progress prop. You can see this case in this commit.

cjhines avatar Sep 14 '22 07:09 cjhines

@vmoroz Can you see if there is a problem here with our JSValueObject types?

jonthysell avatar Sep 15 '22 18:09 jonthysell