Skip to content

Fix NSURLSession delegate instrumentation for NSProxy delegates #14478#15869

Open
JesusRojass wants to merge 4 commits intofirebase:mainfrom
JesusRojass:JesusRojass/#14478
Open

Fix NSURLSession delegate instrumentation for NSProxy delegates #14478#15869
JesusRojass wants to merge 4 commits intofirebase:mainfrom
JesusRojass:JesusRojass/#14478

Conversation

@JesusRojass
Copy link
Contributor

Discussion

Fixes #14478. With Performance instrumentation enabled, NSURLSession delegate callbacks were not delivered when the delegate was an NSProxy (e.g. forwarding to a real delegate). The SDK was instrumenting the proxy instead of the underlying delegate, so optional methods like URLSession:dataTask:didReceiveResponse:completionHandler: were never queried or invoked. This change detects proxy delegates via [delegate isProxy], uses FPRProxyObjectHelper to find the real delegate from the proxy’s ivars, and instruments that object instead.

Testing

Existing Firebase Performance tests pass. Added/updated tests:

  • FPRNSURLSessionDelegateProxy test helper and tests that use it to verify all delegate methods (including didReceiveResponse:completionHandler: and didResumeAtOffset:expectedTotalBytes:) are forwarded and instrumented when the session delegate is an NSProxy.
  • testDelegateURLSessionDownloadDidReceiveResponseCompletionHandler and testProxyDelegateURLSessionDownloadDidReceiveResponseCompletionHandler for the optional data-task response delegate.
  • testDelegateURLSessionDownloadTaskDidResumeAtOffsetExpectedTotalBytes and testProxyDelegateURLSessionDownloadTaskDidResumeAtOffsetExpectedTotalBytes use the delegate’s cancel-and-resume flow; FPRNSURLSessionTestDownloadDelegate now uses a per-instance hasCancelledOnce flag instead of a static dispatch_once_t so both tests run correctly.

API Changes

  • No API Changes

@gemini-code-assist
Copy link
Contributor

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

@JesusRojass
Copy link
Contributor Author

@tejasd @visumickey

Ready for review!!!

@JesusRojass
Copy link
Contributor Author

/gemini review

@gemini-code-assist
Copy link
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@JesusRojass
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an issue where NSURLSession delegate callbacks were not being delivered when the delegate was an NSProxy. The changes introduce a new registerProxy method in FPRObjectInstrumentor and FPRProxyObjectHelper to correctly identify and instrument the real delegate behind the proxy. This ensures that optional delegate methods are properly queried and invoked. The test suite has been updated with new proxy-specific tests to verify the fix.

@tejasd tejasd self-requested a review March 4, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NSURLSession swizzling incompatible with delegate usage via NSProxy

1 participant