Browse Source

Merge pull request #415 from rebello95/networkmonitor-fix

We've started seeing some crashes when using the `CTServiceRadioAccessTechnologyDidChange` notification within `ClientNetworkMonitor ` in production on iOS 12. This is an issue that's been reported in this radar: https://openradar.appspot.com/46873673

To provide a workaround for this problem, I'm adding the option to opt out of the new iOS 12 API and to instead use the stable pre-iOS 12 API.

**I'm planning to release a new version of SwiftGRPC with this fix after it's merged, which is what the second commit of this PR reflects.**
Michael Rebello 6 years ago
parent
commit
7958369a9d

+ 13 - 7
Sources/SwiftGRPC/Core/ClientNetworkMonitor.swift

@@ -27,6 +27,7 @@ import SystemConfiguration
 /// Original issue: https://github.com/grpc/grpc-swift/issues/337
 open class ClientNetworkMonitor {
   private let queue: DispatchQueue
+  private let useNewCellMonitor: Bool
   private let callback: (State) -> Void
   private let reachability: SCNetworkReachability
 
@@ -61,16 +62,21 @@ open class ClientNetworkMonitor {
 
   /// Designated initializer for the network monitor. Initializer fails if reachability is unavailable.
   ///
-  /// - Parameter host:     Host to use for monitoring reachability.
-  /// - Parameter queue:    Queue on which to process and update network changes. Will create one if `nil`.
-  ///                       Should always be used when accessing properties of this class.
-  /// - Parameter callback: Closure to call whenever state changes.
-  public init?(host: String = "google.com", queue: DispatchQueue? = nil, callback: @escaping (State) -> Void) {
+  /// - Parameter host:              Host to use for monitoring reachability.
+  /// - Parameter queue:             Queue on which to process and update network changes. Will create one if `nil`.
+  ///                                Should always be used when accessing properties of this class.
+  /// - Parameter useNewCellMonitor: Whether to use the new cellular monitor introduced in iOS 12.
+  ///                                Due to rdar://46873673 this defaults to false to prevent crashes.
+  /// - Parameter callback:          Closure to call whenever state changes.
+  public init?(host: String = "google.com", queue: DispatchQueue? = nil, useNewCellMonitor: Bool = false,
+               callback: @escaping (State) -> Void)
+  {
     guard let reachability = SCNetworkReachabilityCreateWithName(nil, host) else {
       return nil
     }
 
     self.queue = queue ?? DispatchQueue(label: "SwiftGRPC.ClientNetworkMonitor.queue")
+    self.useNewCellMonitor = useNewCellMonitor
     self.callback = callback
     self.reachability = reachability
     self.startMonitoringReachability(reachability)
@@ -88,7 +94,7 @@ open class ClientNetworkMonitor {
 
   private func startMonitoringCellular() {
     let notificationName: Notification.Name
-    if #available(iOS 12.0, *) {
+    if #available(iOS 12.0, *), self.useNewCellMonitor {
       notificationName = .CTServiceRadioAccessTechnologyDidChange
     } else {
       notificationName = .CTRadioAccessTechnologyDidChange
@@ -102,7 +108,7 @@ open class ClientNetworkMonitor {
   private func cellularDidChange(_ notification: NSNotification) {
     self.queue.async {
       let newCellularName: String?
-      if #available(iOS 12.0, *) {
+      if #available(iOS 12.0, *), self.useNewCellMonitor {
         let cellularKey = notification.object as? String
         newCellularName = cellularKey.flatMap { self.cellularInfo.serviceCurrentRadioAccessTechnology?[$0] }
       } else {

File diff suppressed because it is too large
+ 2293 - 2291
SwiftGRPC-Carthage.xcodeproj/project.pbxproj


+ 25 - 65
SwiftGRPC-Carthage.xcodeproj/xcshareddata/xcschemes/SwiftGRPC-Package.xcscheme

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
    LastUpgradeVersion = "9999"
-   version = "1.7">
+   version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"
       buildImplicitDependencies = "YES">
@@ -32,9 +32,8 @@
             buildForAnalyzing = "YES">
             <BuildableReference
                BuildableIdentifier = "primary"
-               BlueprintIdentifier = "SwiftGRPC::CgRPC"
-               BuildableName = "CgRPC.framework"
-               BlueprintName = "CgRPC"
+               BuildableName = "'$(TARGET_NAME)'"
+               BlueprintName = "Echo"
                ReferencedContainer = "container:SwiftGRPC-Carthage.xcodeproj">
             </BuildableReference>
          </BuildActionEntry>
@@ -46,8 +45,8 @@
             buildForAnalyzing = "YES">
             <BuildableReference
                BuildableIdentifier = "primary"
-               BuildableName = "&apos;lib$(TARGET_NAME)&apos;"
-               BlueprintName = "SwiftGRPCNIO"
+               BuildableName = "'$(TARGET_NAME)'"
+               BlueprintName = "Simple"
                ReferencedContainer = "container:SwiftGRPC-Carthage.xcodeproj">
             </BuildableReference>
          </BuildActionEntry>
@@ -59,8 +58,8 @@
             buildForAnalyzing = "YES">
             <BuildableReference
                BuildableIdentifier = "primary"
-               BuildableName = "&apos;$(TARGET_NAME)&apos;"
-               BlueprintName = "protoc-gen-swiftgrpc"
+               BuildableName = "'$(TARGET_NAME)'"
+               BlueprintName = "EchoNIO"
                ReferencedContainer = "container:SwiftGRPC-Carthage.xcodeproj">
             </BuildableReference>
          </BuildActionEntry>
@@ -72,8 +71,8 @@
             buildForAnalyzing = "YES">
             <BuildableReference
                BuildableIdentifier = "primary"
-               BuildableName = "&apos;$(TARGET_NAME)&apos;"
-               BlueprintName = "Echo"
+               BuildableName = "'lib$(TARGET_NAME)'"
+               BlueprintName = "SwiftGRPCNIO"
                ReferencedContainer = "container:SwiftGRPC-Carthage.xcodeproj">
             </BuildableReference>
          </BuildActionEntry>
@@ -85,9 +84,8 @@
             buildForAnalyzing = "YES">
             <BuildableReference
                BuildableIdentifier = "primary"
-               BlueprintIdentifier = "SwiftGRPC::BoringSSL"
-               BuildableName = "BoringSSL.framework"
-               BlueprintName = "BoringSSL"
+               BuildableName = "'$(TARGET_NAME)'"
+               BlueprintName = "RootsEncoder"
                ReferencedContainer = "container:SwiftGRPC-Carthage.xcodeproj">
             </BuildableReference>
          </BuildActionEntry>
@@ -99,8 +97,8 @@
             buildForAnalyzing = "YES">
             <BuildableReference
                BuildableIdentifier = "primary"
-               BuildableName = "&apos;$(TARGET_NAME)&apos;"
-               BlueprintName = "EchoNIO"
+               BuildableName = "'lib$(TARGET_NAME)'"
+               BlueprintName = "BoringSSL"
                ReferencedContainer = "container:SwiftGRPC-Carthage.xcodeproj">
             </BuildableReference>
          </BuildActionEntry>
@@ -112,8 +110,8 @@
             buildForAnalyzing = "YES">
             <BuildableReference
                BuildableIdentifier = "primary"
-               BuildableName = "&apos;$(TARGET_NAME)&apos;"
-               BlueprintName = "Simple"
+               BuildableName = "'lib$(TARGET_NAME)'"
+               BlueprintName = "CgRPC"
                ReferencedContainer = "container:SwiftGRPC-Carthage.xcodeproj">
             </BuildableReference>
          </BuildActionEntry>
@@ -125,9 +123,8 @@
             buildForAnalyzing = "YES">
             <BuildableReference
                BuildableIdentifier = "primary"
-               BlueprintIdentifier = "SwiftGRPC::SwiftGRPC"
-               BuildableName = "SwiftGRPC.framework"
-               BlueprintName = "SwiftGRPC"
+               BuildableName = "'$(TARGET_NAME)'"
+               BlueprintName = "protoc-gen-swiftgrpc"
                ReferencedContainer = "container:SwiftGRPC-Carthage.xcodeproj">
             </BuildableReference>
          </BuildActionEntry>
@@ -139,17 +136,17 @@
             buildForAnalyzing = "YES">
             <BuildableReference
                BuildableIdentifier = "primary"
-               BuildableName = "&apos;$(TARGET_NAME)&apos;"
-               BlueprintName = "RootsEncoder"
+               BuildableName = "'lib$(TARGET_NAME)'"
+               BlueprintName = "SwiftGRPC"
                ReferencedContainer = "container:SwiftGRPC-Carthage.xcodeproj">
             </BuildableReference>
          </BuildActionEntry>
          <BuildActionEntry
+            buildForAnalyzing = "YES"
             buildForTesting = "YES"
             buildForRunning = "YES"
             buildForProfiling = "YES"
-            buildForArchiving = "YES"
-            buildForAnalyzing = "YES">
+            buildForArchiving = "YES">
             <BuildableReference
                BuildableIdentifier = "primary"
                BlueprintIdentifier = "SwiftProtobuf::SwiftProtobuf"
@@ -164,13 +161,14 @@
       buildConfiguration = "Debug"
       selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
       selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
-      shouldUseLaunchSchemeArgsEnv = "YES">
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      codeCoverageEnabled = "NO">
       <Testables>
          <TestableReference
             skipped = "NO">
             <BuildableReference
                BuildableIdentifier = "primary"
-               BuildableName = "&apos;$(TARGET_NAME)&apos;"
+               BuildableName = "'$(TARGET_NAME)'"
                BlueprintName = "SwiftGRPCNIOTests"
                ReferencedContainer = "container:SwiftGRPC-Carthage.xcodeproj">
             </BuildableReference>
@@ -179,49 +177,11 @@
             skipped = "NO">
             <BuildableReference
                BuildableIdentifier = "primary"
-               BuildableName = "&apos;$(TARGET_NAME)&apos;"
+               BuildableName = "'$(TARGET_NAME)'"
                BlueprintName = "SwiftGRPCTests"
                ReferencedContainer = "container:SwiftGRPC-Carthage.xcodeproj">
             </BuildableReference>
          </TestableReference>
       </Testables>
-      <AdditionalOptions>
-      </AdditionalOptions>
    </TestAction>
-   <LaunchAction
-      buildConfiguration = "Debug"
-      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
-      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
-      launchStyle = "0"
-      useCustomWorkingDirectory = "NO"
-      ignoresPersistentStateOnLaunch = "NO"
-      debugDocumentVersioning = "YES"
-      debugServiceExtension = "internal"
-      allowLocationSimulation = "YES">
-      <MacroExpansion>
-         <BuildableReference
-            BuildableIdentifier = "primary"
-            BlueprintIdentifier = "SwiftGRPC::CgRPC"
-            BuildableName = "CgRPC.framework"
-            BlueprintName = "CgRPC"
-            ReferencedContainer = "container:SwiftGRPC-Carthage.xcodeproj">
-         </BuildableReference>
-      </MacroExpansion>
-      <AdditionalOptions>
-      </AdditionalOptions>
-   </LaunchAction>
-   <ProfileAction
-      buildConfiguration = "Release"
-      shouldUseLaunchSchemeArgsEnv = "YES"
-      savedToolIdentifier = ""
-      useCustomWorkingDirectory = "NO"
-      debugDocumentVersioning = "YES">
-   </ProfileAction>
-   <AnalyzeAction
-      buildConfiguration = "Debug">
-   </AnalyzeAction>
-   <ArchiveAction
-      buildConfiguration = "Release"
-      revealArchiveInOrganizer = "YES">
-   </ArchiveAction>
 </Scheme>

+ 1 - 1
SwiftGRPC.podspec

@@ -11,7 +11,7 @@
 
 Pod::Spec.new do |s|
   s.name = 'SwiftGRPC'
-  s.version = '0.8.0'
+  s.version = '0.8.1'
   s.license     = { :type => 'Apache License, Version 2.0',
                     :text => <<-LICENSE
                       Copyright 2018, gRPC Authors. All rights reserved.

Some files were not shown because too many files changed in this diff