Firebase-ios-sdk: NSURLConnection doesn't call the delegate methods when my app installs Firebase Preformance Monitoring.

Created on 20 Dec 2018  路  14Comments  路  Source: firebase/firebase-ios-sdk

Describe your environment

  • Xcode version: 10.1
  • Firebase SDK version: 5.12.0
  • Firebase Component: Performance
  • Component version: 5.12.0

Describe the problem

My app uses NSURLConnection in a background thread. It was configured a delegate object and expected to call the methods.

    self.connection = [[NSURLConnection alloc] initWithRequest:_request // NSURLRequest
                                                  delegate:self
                                          startImmediately:NO];

     [self.connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
     [self.connection start];
     [[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantFuture]];

This code is in a subclass of NSOperation. It is the delegate object.

@interface FooOperation : NSOperation <NSURLConnectionDelegate, NSURLConnectionDataDelegate>

@property (nonatomic, strong) NSURLConnection *connection;

[self.connection start] is called in overridden "main" method.

- (void)main
{
   //....
}

This pull-request fixed the issue previously occurred, but another one is occurred...

https://github.com/firebase/firebase-ios-sdk/pull/2067

This is a stack trace when NSURLConnection calls 'start' method.

  28 libdispatch.dylib 642738.0  _dispatch_worker_thread2
  27 libdispatch.dylib 642738.0  _dispatch_root_queue_drain
  26 libdispatch.dylib 642738.0  _dispatch_async_redirect_invoke
  25 libdispatch.dylib 642738.0  _dispatch_continuation_pop
  24 libdispatch.dylib 642738.0  _dispatch_client_callout
  23 libdispatch.dylib 642738.0  _dispatch_call_block_and_release
  22 Foundation 642738.0  __NSOQSchedule_f
  21 Foundation 642738.0  -[__NSOperationInternal _start:]
  20 MyApp 642738.0  -[FooOperation main]
  18 MyApp 627878.0  __InstrumentConnectionStart_block_invoke
  17 MyApp 226780.0  +[FPRNetworkTrace addNetworkTrace:toObject:]
  16 MyApp 225464.0  +[GULObjectSwizzler setAssociatedObject:key:value:association:]
  15 libobjc.A.dylib 221984.0  _object_set_associative_reference
  14 libobjc.A.dylib 219655.0  objc_object::sidetable_release(bool)
  13 MyApp 218381.0  -[FPRNetworkTrace dealloc]
  12 libobjc.A.dylib 187294.0  object_dispose
  11 libobjc.A.dylib 186714.0  objc_destructInstance
  10 libobjc.A.dylib 186049.0  object_cxxDestructFromClass(objc_object*, objc_class*)
   9 MyApp 179632.0  -[FPRNetworkTrace .cxx_destruct]
   8 libobjc.A.dylib 143626.0  objc_object::sidetable_release(bool)
   7 MyApp 138355.0  -[FPRTraceBackgroundActivityTracker dealloc]
   6 Foundation 134292.0  -[NSNotificationCenter removeObserver:name:object:]
   5 CoreFoundation 133043.0  _CFXNotificationRemoveObservers
   4 CoreFoundation 115850.0  -[_CFXNotificationRegistrar match:object:observer:enumerator:]
   3 CoreFoundation 37516.0  -[_CFXNotificationNameWildcardObjectRegistration match:matching:]
   2 CoreFoundation 22159.0  CFDictionaryGetValue
   1 CoreFoundation 21641.0  CFBasicHashFindBucket
   0 CoreFoundation 290.0  __hashPtr

GoogleUtilities performance

All 14 comments

Tracked internally at b/121352006

@kazuhiro4949 I'm trying to understand few things here to make sure I debug this right.

  1. I understand you are initiating a call for making a network request in main(). But is this happening after Firebase Initialization?
  2. When you say none of the delegate methods of NSURLConnection are getting called - just to confirm - even connectionDidFinishLoading: is not getting called? Can you share any sample URL for us to test with?

I tried making network requests using NSURLConnection and all the necessary delegates are getting called. I want to make sure we are not missing any specific scenario here.

Closing due to inactivity. We'll reopen with more information.

@visumickey @paulb777
I'm sorry for being late. I made a sample code to reproduce this problem.

https://github.com/kazuhiro4949/PerformanceMonitoringDebug

It works on Xcode 10.1 and Swift 4.2.
Install FirebaseSDK from Cocoapods and take GoogleService-info.plist from your firebase project.
If Firebase.configure() in AppDelegate.swift is removed, FooOperation catches NSURLConnetionDelegate methods and stops the infinity loop.

Implementing automaticallyNotifiesObserversForKey seems to cause that.

Thanks.

Internally tracked at b/127766572

I really appreciate your help.
Do you have any update on this issue?

Thanks

This is currently worked on and hopefully released in the upcoming Perf SDK Release. Will keep this thread updated.

After a lot of investigation, I'm confident that this is an issue with the GULSwizzler. The current issue is because of the scenario when NSOperation (derived class) implements "automaticallyNotifiesObserversForKey", the swizzler seem to loose reference of the delegate object and so the delegate object does not receive any updates. I'm working with the Swizzler library/people to get this resolved at the earliest.

This is fixed and should be available in the upcoming release.

Thanks!

@visumickey do we have a date for when 6.6.0 should be live?

@MikeSilvis The release is expected to happen before August 9th (this weekend). Will keep you posted as I hear the updates.

@MikeSilvis Firebase 6.6.0 has published to CocoaPods. The zip and Carthage releases will be updated later today.

Was able to confirm this fixed our SDK. Thanks

Was this page helpful?
0 / 5 - 0 ratings