From 91c5ff4a12982ccead56c9c038761e9316d01409 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Tue, 17 Mar 2020 14:52:59 -0700 Subject: [PATCH] Guard against nil methodQueue in RCTBlobManager Summary: ## Description In T63516227, we're seeing a crash that occurs because `networking.methodQueue` is `nil`, and we try to `dispatch_async` to it. ## Hypothesis This looks like a problem with NativeModule cleanup: 1. Some JS executes a call to `RCTBlobManager.addNetworkingHander`. This schedules an async method call on the `RCTBlobManager` method queue. 2. In `RCTCxxBridge invalidate`, on the JS thread, we loop through all the `RCTModuleData`s, and invalidate them. This invalidates our NativeModules (perhaps not all but only `RCTNetworking`). 3. The `RCTBlobManager.addNetworkingHander` method call finally executes, with `RCTNetworking`'s methodQueue set to nil, which throws this error. Changelog: [iOS][Fixed] - Fix RCTBlobManager cleanup crash Reviewed By: PeteTheHeat Differential Revision: D20498096 fbshipit-source-id: d2d60984637ddf883278289258aa9b2ae81bb172 --- Libraries/Blob/RCTBlobManager.mm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Libraries/Blob/RCTBlobManager.mm b/Libraries/Blob/RCTBlobManager.mm index e47ea488df5..c41c75ed5e4 100755 --- a/Libraries/Blob/RCTBlobManager.mm +++ b/Libraries/Blob/RCTBlobManager.mm @@ -142,6 +142,12 @@ RCT_EXPORT_METHOD(addNetworkingHandler) { RCTNetworking *const networking = _bridge ? _bridge.networking : [_turboModuleLookupDelegate moduleForName:"RCTNetworking"]; + // TODO(T63516227): Why can methodQueue be nil here? + // We don't want to do anything when methodQueue is nil. + if (!networking.methodQueue) { + return; + } + dispatch_async(networking.methodQueue, ^{ [networking addRequestHandler:self]; [networking addResponseHandler:self];