microsoft / react-native-windows

A framework for building native Windows apps with React.
https://microsoft.github.io/react-native-windows/
Other
16.14k stars 1.13k forks source link

avmoroz/react-native-fs crashing on downloadFile #10501

Open cjhines opened 1 year ago

cjhines commented 1 year ago

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

chrisglein commented 1 year ago

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

cjhines commented 1 year ago

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 commented 1 year ago

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
chrisglein commented 1 year ago

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 commented 1 year ago

@vmoroz FYI

cjhines commented 1 year ago

@chrisglein

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

Screenshot 2022-09-13 at 18 09 33
cjhines commented 1 year ago

@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.

jonthysell commented 1 year ago

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