A few days ago, ayende put up a post showing a bug that had been found in RavenDb that was causing the profiling tools to enter an infinite loop.
This was followed by a post about how this bug had come into being and survived so long.
So confession time, that’s my bug. I contributed the early code for the profiler.
So since then I have been trying to work out how I missed it. Was I really so oblivious to what was going on while writing that code?
Second to that, how had it sat in production on ayende’s blog for 6 months or so without being noticed?
I am glad to say I have an explanation for both, which I will share now.
First some background on how the profiling actually works.
When you attach your DocumentStore to the profile, the following code is run
Basically we attach to the OnSessionCreated event and stuff a header into the response with the session id.
This is very important, and the key to why this bug was missed. So I will say it again, the X-RavenDb-Profiling-Id header is only added to your response if you actually open a session.
It only calls back to the server when it gets an AJAX response that has the header set. So if you make an AJAX request to your server for data that does not come from RavenDb, the profiler will not pay any attention to that request.
The request to get the profiling results does not need a session, and in all my development it did not create a session. So it never set the header. So it never entered a loop.
So that explained to me how I had missed the bug, the way I deal with session management (creating and disposing of them only as needed) simply does not trigger the bug.
So with my conscience cleared, I moved on to the second problem. Just because I handle my session this way, clearly RacoonBlog does not, surely that bug hasn’t been there since ayende turned on the profiler for his blog.
Well let me present a commit to the RacoonBlog source from the very end of December.
So until that commit was pushed live RacoonBlog, like my own sites, simply did not trigger this bug, it was sitting there dormant just waiting for someone to take a different approach to session management.
So there we have it. I really don’t feel so bad about it now.