Skip to content

NSURLConnection doesn't call the delegate methods when my app installs Firebase Preformance Monitoring. #2201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kazuhiro4949 opened this issue Dec 20, 2018 · 14 comments

Comments

@kazuhiro4949
Copy link

kazuhiro4949 commented Dec 20, 2018

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...

#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

@kazuhiro4949 kazuhiro4949 changed the title NSURLConnection doesn't call the delegate methods when my app install Firebase Preformance Monitoring. NSURLConnection doesn't call the delegate methods when my app installs Firebase Preformance Monitoring. Dec 20, 2018
@firebase firebase deleted a comment from google-oss-bot Dec 21, 2018
@paulb777
Copy link
Member

Tracked internally at b/121352006

@visumickey
Copy link
Contributor

@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.

@paulb777
Copy link
Member

paulb777 commented Feb 6, 2019

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

@paulb777 paulb777 closed this as completed Feb 6, 2019
@kazuhiro4949
Copy link
Author

kazuhiro4949 commented Feb 7, 2019

@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.

@morganchen12 morganchen12 reopened this Feb 7, 2019
@visumickey
Copy link
Contributor

Internally tracked at b/127766572

@kazuhiro4949
Copy link
Author

kazuhiro4949 commented May 14, 2019

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

Thanks

@visumickey
Copy link
Contributor

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

@visumickey
Copy link
Contributor

visumickey commented May 28, 2019

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.

@visumickey
Copy link
Contributor

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

@kazuhiro4949
Copy link
Author

Thanks!

@visumickey visumickey added this to the 6.6.0 milestone Aug 1, 2019
@MikeSilvis
Copy link

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

@visumickey
Copy link
Contributor

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

@paulb777
Copy link
Member

paulb777 commented Aug 7, 2019

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

@MikeSilvis
Copy link

Was able to confirm this fixed our SDK. Thanks

@firebase firebase locked and limited conversation to collaborators Oct 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants