From 35c1c27bf6a46fd7c273e9ff74061577f8df4313 Mon Sep 17 00:00:00 2001 From: Mehdi Mulani Date: Mon, 12 Nov 2018 10:43:19 -0800 Subject: [PATCH] NetInfo: try to solve crash with releasing _firstTimeReachability Summary: @public We're seeing a crash on line 191 when we do `CFRelease(self->_firstTimeReachability);`. My thinking is that there's a race condition between the deallocation coming from calling `getCurrentConnectivity` twice in a row and the callback coming back. Reviewed By: PeteTheHeat Differential Revision: D12982772 fbshipit-source-id: d3d882a074b67a5e547e7f480f561fcaf8d79ec4 --- Libraries/Network/RCTNetInfo.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Libraries/Network/RCTNetInfo.m b/Libraries/Network/RCTNetInfo.m index 40e164d33d2275..8ecbf889bd2eae 100644 --- a/Libraries/Network/RCTNetInfo.m +++ b/Libraries/Network/RCTNetInfo.m @@ -69,6 +69,13 @@ static void RCTReachabilityCallback(__unused SCNetworkReachabilityRef target, SC } } +// We need RCTReachabilityCallback's and module methods to be called on the same thread so that we can have +// guarantees about when we mess with the reachability callbacks. +- (dispatch_queue_t)methodQueue +{ + return dispatch_get_main_queue(); +} + #pragma mark - Lifecycle - (instancetype)initWithHost:(NSString *)host