Skip to content

Fix NSURLSession delegate instrumentation for NSProxy delegates #14478 - #15869

Merged
tejasd merged 17 commits into
firebase:mainfrom
JesusRojass:JesusRojass/#14478
Apr 15, 2026
Merged

Fix NSURLSession delegate instrumentation for NSProxy delegates #14478#15869
tejasd merged 17 commits into
firebase:mainfrom
JesusRojass:JesusRojass/#14478

Conversation

@JesusRojass

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
Member Author

@tejasd @visumickey

Ready for review!!!

@JesusRojass

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

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

@JesusRojass

Copy link
Copy Markdown
Member Author

/gemini review

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

Copy link
Copy Markdown
Contributor

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.

Comment thread FirebasePerformance/Sources/Instrumentation/FPRObjectInstrumentor.h Outdated
Comment thread FirebasePerformance/Sources/Instrumentation/FPRProxyObjectHelper.h Outdated
Comment thread FirebasePerformance/Sources/Instrumentation/Network/FPRNSURLSessionInstrument.m Outdated
Comment thread FirebasePerformance/Tests/Unit/Instruments/FPRNSURLSessionInstrumentTest.m Outdated
@tejasd
tejasd self-requested a review March 4, 2026 18:09
Comment thread FirebasePerformance/CHANGELOG.md
@JesusRojass
JesusRojass requested a review from tejasd April 13, 2026 22:49
@JesusRojass

Copy link
Copy Markdown
Member Author

Hey there @tejasd

Thank you so much for the review!

I have addressed your comments and made changes!
thanks!

Comment thread FirebasePerformance/Sources/Instrumentation/FPRObjectInstrumentor.h
@JesusRojass
JesusRojass requested a review from tejasd April 15, 2026 18:12
@JesusRojass

Copy link
Copy Markdown
Member Author

Comments addressed @tejasd

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

2 participants