square / PonyDebugger

Remote network and data debugging for your native iOS app using Chrome Developer Tools
Other
5.86k stars 595 forks source link

Fix Network Debugging Swizzle Guard #144

Closed ryanolsonk closed 9 years ago

ryanolsonk commented 9 years ago

This fixes #141 raised by @mthole

There was previously no working guard against sniffing the same network event multiple times. This can happen when we swizzle both a class and a superclass that implement one of the delegate methods. Previously, we would log duplicate network events if the class called through to the swizzled method on its superclass. By detecting nested calls, we now avoid the duplicated sniffing.

The issue isn't limited to passing messages up to the superclass, but happens with any forwarding from inside the delegate callback. For example, AFNetworking uses internal delegate objects in AFURLSessionManager (see https://github.com/AFNetworking/AFNetworking/blob/master/AFNetworking/AFURLSessionManager.m#L109). If forwardAllNetworkTraffic is used, we'll swizzle the methods on both AFURLSessionManager and AFURLSessionManagerTaskDelegate. We need a guard to ensure we only sniff the network event for the first delegate call, and ignore it on any nested forwarding.

mthole-old commented 9 years ago

Awesome, thanks for digging into this @ryanolsonk. I'll take a look this weekend.

mthole-old commented 9 years ago

LGTM

mthole-old commented 9 years ago

FYI, released v0.4.2 to CocoaPods with this fix. Thanks again, @ryanolsonk !

ryanolsonk commented 9 years ago

:thumbsup: Thanks @mthole