square / PonyDebugger

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

HTTP response body data double-logged for NSURLSession-based response #141

Closed mthole-old closed 9 years ago

mthole-old commented 9 years ago

When using an NSURLSession-based connection (e.g. AFNetworking 2.0), PonyDebugger is reporting invalid JSON response bodies. After a little investigation, I see that the JSON response body is actually double-logged, making it invalid JSON. (This prevents the Chrome tools built-in display of the JSON as an object, etc.)

I did a bit more digging and found that [PDNetworkDomainController addAccumulatedData:forTask:] is being called twice with the same data for the same task -- once in the "running" state and once in the "completed" state.

I suspect this has to do with the recent-ish changes for support NSURLSession connections.

mthole-old commented 9 years ago

@viteinfinite, could you take a look?

mthole-old commented 9 years ago

See https://github.com/square/PonyDebugger/tree/mthole/NSURLSession-workaround for a potential -- lucky likely wrong -- fix.

mthole-old commented 9 years ago

Digging into this more: I think PonyDebugger is getting swizzled-callbacks for didReceiveData multiple times for the same data task, due to the class hierarchy I'm working with? If I use forwardNetworkTrafficFromDelegateClass: rather than forwardAllNetworkTraffic:, things seem to work correctly. Hmm.

mthole-old commented 9 years ago

This issue was the result of over-eagerly-swizzling, causing and multiple notifications to be posted to the data accumulator. I'm not sure it's worth debugging that further, so I'll go ahead and close this issue. (I resolved my issue by switching to forwardNetworkTrafficFromDelegateClass:, a more targeted approach.)

ryanolsonk commented 9 years ago

I've also been running into this issue. I'll post back if I find a solution. I'd like to continue using forwardAllNetworkTraffic:.