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

RCTBlobManager handleNetworkingRequest React native IOS

Open marquinmpfs opened this issue 2 years ago • 2 comments

Description

I have an error only on iOS to upload the image, on android it goes normally.

In another app I made, I use the same format to send the bytes of a uri, but since this one is on a newer version (0.70.4), I'm getting this error.

I've tried everything, but I don't know how to solve it, does anyone have an idea?

Apparently the problem is with:

const img = await fetch(path);

const bytes = await img.blob();

image

LOG iOS:

0x18f03b404 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:].cold.5 + 52 (NSPlaceholderDictionary.m:71)
0x18eee1e94 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 320 (NSPlaceholderDictionary.m:71)
0x18ef00ae8 +[NSDictionary dictionaryWithObjects:forKeys:count:] + 60 (NSDictionary.m:609)
x1049d6b20 -[RCTBlobManager handleNetworkingRequest:] + 432 (RCTBlobManager.mm:270)
x1049eec10 -[RCTNetworking processDataForHTTPQuery:callback:] + 272 (RCTNetworking.mm:385)
x1049ee470 -[RCTNetworking buildRequest:completionBlock:] + 1140 (RCTNetworking.mm:318)
x1049f16bc -[RCTNetworking sendRequest:callback:] + 844 (RCTNetworking.mm:704)

I would like to upload the image correctly in firebase, the version I'm using is v9.

Version

0.70.4

Output of npx react-native info

System: OS: macOS 11.3.1 CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz Memory: 78.36 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 18.0.0 - /usr/local/bin/node Yarn: 1.22.19 - ~/Developer/app/node_modules/.bin/yarn npm: 8.6.0 - /usr/local/bin/npm Watchman: 2022.03.21.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 Android SDK: API Levels: 28, 29, 30, 31, 32, 33 Build Tools: 28.0.3, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0, 33.0.0 System Images: android-29 | Intel x86 Atom, android-29 | Intel x86 Atom_64, android-29 | Google APIs ARM 64 v8a, android-29 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom_64, android-32 | Google APIs ARM 64 v8a, android-32 | Google APIs Intel x86 Atom_64, android-32 | Google Play ARM 64 v8a, android-32 | Google Play Intel x86 Atom_64 Android NDK: Not Found IDEs: Android Studio: 2021.2 AI-212.5712.43.2112.8512546 Xcode: 12.4/12D4e - /usr/bin/xcodebuild Languages: Java: 11.0.16.1 - /Users/mpfs/.jenv/shims/javac npmPackages: @react-native-community/cli: Not Found react: 18.1.0 => 18.1.0 react-native: 0.70.4 => 0.70.4 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

Get uri image and call fuction:

static async uploadFile(path, fileName) {
    const img = await fetch(path);
    const bytes = await img.blob();
    const storageRef = refStore(storage, `${fileName}`);

    return new Promise(async (resolve, reject) => {
      try {
        await uploadBytes(storageRef, bytes);
        const uriImageURL = await getDownloadURL(storageRef);
        resolve(uriImageURL);
      } catch (error) {
        reject(new Error('Erro ao obter na url da imagem.'));
      }
    });
  }

After call this function with firebase, an error return sometimes the problem doesn't happen, but most of the time it does.

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

image

image

2022-10-26 20:29:14.451882-0300 app[44802:714446] [native] Exception '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]' was thrown while invoking sendRequest on target Networking with params ( { data = { blob = { "__collector" = { }; blobId = "863e985c-8801-48fb-a5b2-a5a4a3a01a36"; lastModified = 1666826954441; offset = 0; size = 4395567; type = ""; }; trackingName = unknown; }; headers = { authorization = "Firebase eyJhbGciOiJSUzI1NiIsImtpZCI6IjNmNjcyNDYxOTk4YjJiMzMyYWQ4MTY0ZTFiM2JlN2VkYTY4NDZiMzciLCJ0eXAiOiJKV1QifQ-T06wzO6dp82_e8L54q4Zpu4xeYwZ5NBeRLv_wlRgUh8Acr965YUo1jp88z_kRwV9aYlqLLmMLnn-"; "content-type" = "multipart/related; boundary=4135395071452938605408416319345968"; "x-firebase-storage-version" = "webjs/9.10.0"; "x-goog-upload-protocol" = multipart; }; incrementalUpdates = 0; method = POST; responseType = text; timeout = 0; url = "https://firebasestorage.googleapis.com/v0/b/app.appspot.com/o?name=users/xpto.jpg"; withCredentials = 1; }, 5751 ) callstack: ( 0 CoreFoundation 0x00007fff20421af6 __exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007fff20177e78 objc_exception_throw + 48 2 CoreFoundation 0x00007fff2049e77f _CFThrowFormattedException + 194 3 CoreFoundation 0x00007fff204a9ec4 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:].cold.5 + 0 4 CoreFoundation 0x00007fff2048ccb7 -[_NSPlaceholderDictionary initWithObjects:forKeys:count:] + 235 5 CoreFoundation 0x00007fff20420773 +[NSDictionary dictionaryWithObjects:forKeys:count:] + 49 6 app 0x000000010700465e -[RCTBlobManager handleNetworkingRequest:] + 862 7 app 0x000000010703cffc -[RCTNetworking processDataForHTTPQuery:callback:] + 1692 8 app 0x000000010703bde2 -[RCTNetworking buildRequest:completionBlock:] + 3746 9 app 0x0000000107042dee -[RCTNetworking sendRequest:callback:] + 1406 10 CoreFoundation 0x00007fff204282fc invoking + 140 11 CoreFoundation 0x00007fff204257b6 -[NSInvocation invoke] + 303 12 CoreFoundation 0x00007fff20425a47 -[NSInvocation invokeWithTarget:] + 70 13 app 0x0000000106eed937 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2599 14 app 0x0000000106ef1e8c _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicEiN12_GLOBAL__N_117SchedulingContextE + 1436 15 app 0x0000000106ef171e _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 158 16 app 0x0000000106ef1679 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 25 17 libdispatch.dylib 0x000000010a8b57ec _dispatch_call_block_and_release + 12 18 libdispatch.dylib 0x000000010a8b69c8 _dispatch_client_callout + 8 19 libdispatch.dylib 0x000000010a8bd296 _dispatch_lane_serial_drain + 796 20 libdispatch.dylib 0x000000010a8bdf67 _dispatch_lane_invoke + 439 21 libdispatch.dylib 0x000000010a8c9de2 _dispatch_workloop_worker_thread + 882 22 libsystem_pthread.dylib 0x00007fff611684c0 _pthread_wqthread + 314 23 libsystem_pthread.dylib 0x00007fff61167493 start_wqthread + 15 )

marquinmpfs avatar Oct 26 '22 23:10 marquinmpfs

Any solution to this problem?

marquinmpfs avatar Nov 02 '22 21:11 marquinmpfs

I started looking into this due to https://github.com/firebase/firebase-js-sdk/issues/5848. I found that the issue is due to the fact that when the data is being sent out, the blob isn't yet stored in the dictionary:https://github.com/facebook/react-native/blob/44f3234d1f4d21f779f2dfb3b9dbe16249e7c9d2/Libraries/Blob/RCTBlobManager.mm#L100

My logs confirm this:

2022-11-04 15:12:12.287996-0700 firebasestoragecrash[16854:3273269] Checking BlobID: 81f81a15-1ff0-4a95-9aab-e343b7a54e55
2022-11-04 15:12:12.288646-0700 firebasestoragecrash[16854:3273269] Blob Not available
2022-11-04 15:12:12.718696-0700 firebasestoragecrash[16854:3273266] Storing with id 81f81a15-1ff0-4a95-9aab-e343b7a54e55

And the crash happens right after that.

maneesht avatar Nov 04 '22 22:11 maneesht

I started looking into this due to firebase/firebase-js-sdk#5848. I found that the issue is due to the fact that when the data is being sent out, the blob isn't yet stored in the dictionary:

https://github.com/facebook/react-native/blob/44f3234d1f4d21f779f2dfb3b9dbe16249e7c9d2/Libraries/Blob/RCTBlobManager.mm#L100

My logs confirm this:

2022-11-04 15:12:12.287996-0700 firebasestoragecrash[16854:3273269] Checking BlobID: 81f81a15-1ff0-4a95-9aab-e343b7a54e55
2022-11-04 15:12:12.288646-0700 firebasestoragecrash[16854:3273269] Blob Not available
2022-11-04 15:12:12.718696-0700 firebasestoragecrash[16854:3273266] Storing with id 81f81a15-1ff0-4a95-9aab-e343b7a54e55

And the crash happens right after that.

This issue I had tried to do the way he did by doing the patch, but in my case it didn't work.

Do you know any solution for this case?

marquinmpfs avatar Nov 08 '22 23:11 marquinmpfs

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar May 10 '23 06:05 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar May 17 '23 18:05 github-actions[bot]

Any news on this ?, experiencing the same thing

jb-san avatar Jul 19 '24 08:07 jb-san