SamSaffron / MiniProfiler

A simple but effective mini-profiler for ASP.NET MVC, ASP.NET and Ruby.
http://miniprofiler.com
1.05k stars 221 forks source link

Fixes infinite recursion issue when re-using XmlHttpRequest objects. #195

Closed jcoutch closed 4 years ago

jcoutch commented 10 years ago

I ran into a strange situation where I was getting stack overflow and out of memory errors from JavaScript when having both MiniProfiler and Angular included in my project. The cause seems to be a re-use of XmlHttpRequest somewhere in either my code, or another third party library. The original AngularJS logic in StackExchange.Profiling\UI\includes.js didn't have conditional checks to ensure the onreadystatechange override didn't get added multiple times, so when "send" would get called a second time, it would overwrite this._onreadystatechange with the old method. Since that variable would be considered a pointer reference, the overridden onreadystatechange would recursively call itself.

The changes added below detects if the onreadystatechange event has already been overridden by MiniProfiler, and if not, executes the existing logic. Also, I changed the location of this._onreadystatechange to this.miniprofiler.old_onreadystatechange, since there's a good possibility another script could be using the"_onreadystatechange" variable name, and we don't want MiniProfiler introducing inconsistencies in third party libraries (and vice versa.)

dixon commented 10 years ago

We have moved this project to https://github.com/MiniProfiler/dotnet - would you please make your changes there? Thank you!

In your specific case, the https://github.com/MiniProfiler/ui repo is a submodule in the /dotnet repo, so there might be multiple pull requests for your includes.js change (I'm a bit of a git noob; not sure on pull requests involving submodules).

jcoutch commented 4 years ago

Totally missed this message...my bad! Looks like it got pulled into the correct repo though, so I'll close this request.