﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com/blog/</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2012 (c) 2012</copyright><ttl>60</ttl><item><title>A bad test</title><description>&lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/A-bad-test_14ECA/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/A-bad-test_14ECA/image_thumb.png" width="953" height="327"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This is a bad test, because what it does is ensuring that something &lt;em&gt;does not works&lt;/em&gt;. I just finished implementing the session.Advaned.Defer support, and this test got my attention by failing the build.&lt;/p&gt; &lt;p&gt;&lt;em&gt;Bad &lt;/em&gt;test, you should be telling me when I broke something, not when I added new functionality.&lt;/p&gt;</description><link>http://ayende.com/blog/155617/a-bad-test?key=681dcdab-232a-40a7-bb7a-50def0640d9b</link><guid>http://ayende.com/blog/155617/a-bad-test?key=681dcdab-232a-40a7-bb7a-50def0640d9b</guid><pubDate>Fri, 18 May 2012 09:00:00 GMT</pubDate></item><item><title>Non overlapping time periods&amp;ndash;because I like the pain of 2 AM wakeup calls</title><description>&lt;p&gt;
	This post is partly in response for &lt;a href="http://codebetter.com/johnvpetersen/2012/03/13/229-the-case-of-the-missing-data-point-and-the-curious-thing-a-leap-year-is/"&gt;this post&lt;/a&gt;, discussing the Azure problem with leap year. But it is actually a bit more general than that.&lt;/p&gt;
&lt;p&gt;
	In my code, here is how I define &amp;ldquo;one year from now&amp;rdquo;:&lt;/p&gt;
&lt;blockquote&gt;
	&lt;p&gt;
		DateTime.Today.AddYears(1).AddDays(3);&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
	As it turned out, this tend to have a lot of implications on your business, most of them are actually pretty good ones.&lt;/p&gt;
&lt;p&gt;
	For a start, you will never get hit with a leap year bug, but more importantly, you are never going to have to deal with an immediate cutoff. This is important because it gives you time. Mostly, it gives you time to screw up, but having the time to do so without having an egg all of your face is a really nice thing.&lt;/p&gt;
&lt;p&gt;
	For example, all of our subscriptions are using a similar method of calculation, and this is why we can take the ordering system down for a few hours or even a day or two and no one will actually notice. We have a big grace period in which we can work things out.&lt;/p&gt;
&lt;p&gt;
	Sure, a user gets 3 &amp;ldquo;extra&amp;rdquo; days for free out of this, but frankly, I don&amp;rsquo;t give a damn. It is more important that I get the buffer, and most users like it much better when you don&amp;rsquo;t slam the doors in their faces on the first chance.&lt;/p&gt;
&lt;p&gt;
	One of the things that is important is &lt;em&gt;style&lt;/em&gt;, and giving a grace period for those sort of things is crucial.&lt;/p&gt;
</description><link>http://ayende.com/blog/155521/non-overlapping-time-periodsndash-because-i-like-the-pain-of-2-am-wakeup-calls?key=d3ef0b84-4bb5-4f6a-9679-6759e89eef46</link><guid>http://ayende.com/blog/155521/non-overlapping-time-periodsndash-because-i-like-the-pain-of-2-am-wakeup-calls?key=d3ef0b84-4bb5-4f6a-9679-6759e89eef46</guid><pubDate>Tue, 15 May 2012 09:00:00 GMT</pubDate></item><item><title>Rotten Scheduling: Don&amp;rsquo;t roll your own</title><description>&lt;p&gt;“We need to run a specific task every 72 hours, I thought about this approach…”&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; TimedTask
{
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Timer Timer;
  
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Init()
  {
    Timer = &lt;span class="kwrd"&gt;new&lt;/span&gt; Timer(ExecuteEvery72Hours, &lt;span class="kwrd"&gt;null&lt;/span&gt;, TimeSpan.FromHours(72), TimeSpan.FromHours(72));
  }
  
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ExecuteEvery72Hours()
  {
    &lt;span class="rem"&gt;// do something important&lt;/span&gt;
  }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is a bloody rotten idea, let us see why…&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What happens if your application is recycled every 29 hours?&lt;/li&gt;
&lt;li&gt;What happens if your application is always on, but during that 72 hour call, it was offline?&lt;/li&gt;
&lt;li&gt;What happens if your task actually takes more than 72 hours to run?&lt;/li&gt;
&lt;li&gt;What happens if the task fails? &lt;/li&gt;
&lt;li&gt;How do you report errors, warnings, etc?&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Scheduling is a &lt;em&gt;hard &lt;/em&gt;problem. There are a &lt;em&gt;lot&lt;/em&gt; of things that you actually need to consider. And the code above is really considering none of them. I would be very surprised if something like that &lt;em&gt;ever&lt;/em&gt; run. in production. It most certainly can’t be made to run reliably.&lt;/p&gt;
&lt;p&gt; Things that run every X time, where X is a long time (hours / days) tend to be pretty important. In some of the systems that we wrote, that include doing things like updating VAT and interest rates, pulling from external source, generating the weekly report, etc.&lt;/p&gt;
&lt;p&gt;You do &lt;em&gt;not&lt;/em&gt; want this to be messed up.&lt;/p&gt;
&lt;p&gt;If you need to do anything like that, make use of the builtin scheduling features of the OS you are running on (Windows Task Scheduler is an amazingly full featured, and cron isn’t bad if you are running on Linux). If you still insist on doing this in code, at the very least do something like this:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; TimedTask
{
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Timer Timer;
  
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Init()
  {
    Timer = &lt;span class="kwrd"&gt;new&lt;/span&gt; Timer(()=&amp;gt;
    {
      &lt;span class="kwrd"&gt;if&lt;/span&gt;( (DateTime.UtcNow - GetLastExecutedTime()) &amp;gt; 72)
        ExecuteEvery72Hours();
    }, &lt;span class="kwrd"&gt;null&lt;/span&gt;, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
  }
  
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ExecuteEvery72Hours()
  {
    &lt;span class="rem"&gt;// do something important&lt;/span&gt;
  }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;This still has a lot of problems, but at least it it solving some crucial problems for you (note that GetLastExecutedTime has to be a persisted value).&lt;/p&gt;
&lt;p&gt;Of course, if you need something like this in your code, you have better use something like Quartz, instead. Don’t roll your own. Sure, this is ten lines of code to do so, but as I said, this is the very basics, and it gets complex &lt;em&gt;really &lt;/em&gt;fast.&lt;/p&gt;</description><link>http://ayende.com/blog/155489/rotten-scheduling-donrsquo-t-roll-your-own?key=89b941e1-86d7-443e-a93c-28ed0703bfc2</link><guid>http://ayende.com/blog/155489/rotten-scheduling-donrsquo-t-roll-your-own?key=89b941e1-86d7-443e-a93c-28ed0703bfc2</guid><pubDate>Mon, 14 May 2012 09:00:00 GMT</pubDate></item><item><title>Rotten Scheduling</title><description>&lt;p&gt;“We need to run a specific task every 72 hours, I thought about this approach…”&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; TimedTask
{
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Timer Timer;
  
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Init()
  {
    Timer = &lt;span class="kwrd"&gt;new&lt;/span&gt; Timer(ExecuteEvery72Hours, &lt;span class="kwrd"&gt;null&lt;/span&gt;, TimeSpan.FromHours(72), TimeSpan.FromHours(72));
  }
  
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ExecuteEvery72Hours()
  {
    &lt;span class="rem"&gt;// do something important&lt;/span&gt;
  }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;Let us assume that this code is being called properly. Why is this a bloody rotten idea?&lt;/p&gt;</description><link>http://ayende.com/blog/155457/rotten-scheduling?key=47a203dc-eb07-448a-82e3-2c1919704db3</link><guid>http://ayende.com/blog/155457/rotten-scheduling?key=47a203dc-eb07-448a-82e3-2c1919704db3</guid><pubDate>Fri, 11 May 2012 09:00:00 GMT</pubDate></item><item><title>The best multi threading debugging tool is Microsoft Excel</title><description>&lt;p&gt;In any system that gets to a certain size, especially one that is multi threaded, there are a certain class of bugs that are &lt;em&gt;really &lt;/em&gt;a bitch to figure out. &lt;/p&gt; &lt;p&gt;They are usually boil down to some sort of a race condition. I have been doing that recently, trying to fix a bunch of race conditions in RavenDB. The problem with race conditions is that they are incredibly hard to reproduce, and even when you can reproduce them, you can’t really &lt;em&gt;debug them&lt;/em&gt;. &lt;/p&gt; &lt;p&gt;I came up with the following test harness to try to &lt;a href="https://github.com/ayende/ravendb/blob/27564b0e543051b298f8716e5934c7bea812a4df/Raven.Tryouts/Program.cs"&gt;narrow things down&lt;/a&gt;. Basically, create a test case that sometimes fails, and run it a thousand times.&lt;/p&gt; &lt;p&gt;Odds are that you’ll get the failure, but that isn’t the important bit. The important bit is that you setup logging properly. In my case, I set things up so the logging output to CSV and each test run had a different file.&lt;/p&gt; &lt;p&gt;This gives me output that looks like this:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;23:54:34.5952,Raven.Database.Server.HttpServer,Debug,Request #&amp;nbsp; 10: GET&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp; 12 ms - &amp;lt;default&amp;gt;&amp;nbsp; - 200 - /indexes/dynamic/Companies?query=&amp;amp;start=0&amp;amp;pageSize=1&amp;amp;aggregation=None,,11&lt;br&gt;23:54:34.5952,Raven.Client.Document.SessionOperations.QueryOperation,Debug,"Stale query results on non stale query '' on index 'dynamic/Companies' in '&lt;a href="http://reduction:8079/'"&gt;http://reduction:8079/'&lt;/a&gt;, query will be retried, index etag is: bcf0fed1-d975-43b4-bfb7-65221ef06b99",,1&lt;br&gt;23:54:34.5952,Raven.Database.Indexing.WorkContext,Debug,"No work was found, workerWorkCounter: 10, for: TasksExecuter, will wait for additional work",,6&lt;br&gt;23:54:34.5952,Raven.Database.Indexing.WorkContext,Debug,Incremented work counter to 11 because: WORK BY IndexingExecuter,,12&lt;br&gt;23:54:34.5952,Raven.Database.Indexing.WorkContext,Debug,"No work was found, workerWorkCounter: 11, for: TasksExecuter, will wait for additional work",,6&lt;br&gt;23:54:34.5952,Raven.Database.Indexing.WorkContext,Debug,"No work was found, workerWorkCounter: 11, for: ReducingExecuter, will wait for additional work",,21&lt;br&gt;23:54:34.5952,Raven.Database.Indexing.WorkContext,Debug,"No work was found, workerWorkCounter: 11, for: IndexingExecuter, will wait for additional work",,12&lt;br&gt;23:54:34.6952,Raven.Client.Document.SessionOperations.QueryOperation,Debug,Executing query '' on index 'dynamic/Companies' in '&lt;a href="http://reduction:8079/',,1"&gt;http://reduction:8079/',,1&lt;/a&gt;&lt;br&gt;23:54:34.8172,Raven.Database.Indexing.Index.Querying,Debug,Issuing query on index Temp/Companies for all documents,,11&lt;br&gt;23:54:34.8172,Raven.Storage.Esent.StorageActions.DocumentStorageActions,Debug,Document with key 'companies/1' was found,,11&lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Not really helpful in figure out what is going on, right? Except for one tiny thing, we load them to Excel, and we use conditional formatting to get things to look like this:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/The-best-multi-threading-debugging-tool_1502F/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/The-best-multi-threading-debugging-tool_1502F/image_thumb.png" width="1239" height="544"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The reason this is so helpful? You can actually see the threads interleaving. This usually help me get to roughly the right place, and then I can add additional logging so I can figure out better what is &lt;em&gt;actually&lt;/em&gt; going on.&lt;/p&gt; &lt;p&gt;I was able to detect and fix several race conditions using this approach. &lt;/p&gt; &lt;p&gt;And yes, I know that this is basically printf() debugging. But at least it is printf() debugging with pretty colors.&lt;/p&gt;</description><link>http://ayende.com/blog/154817/the-best-multi-threading-debugging-tool-is-microsoft-excel?key=4868300a-e80b-4c00-9fc8-84f988cf16a4</link><guid>http://ayende.com/blog/154817/the-best-multi-threading-debugging-tool-is-microsoft-excel?key=4868300a-e80b-4c00-9fc8-84f988cf16a4</guid><pubDate>Wed, 09 May 2012 09:00:00 GMT</pubDate></item><item><title>Thou shall not delete</title><description>&lt;p&gt;Ouch!&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult DeleteComment(&lt;span class="kwrd"&gt;int&lt;/span&gt; id)
{
  var userComment = RavenSession.Load&amp;lt;UserComment&amp;gt;(id);

  &lt;span class="kwrd"&gt;if&lt;/span&gt; (userComment == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; HttpStatusCodeResult(204);

  var user = RavenSession.GetUser(User.Identity.Name);
  &lt;span class="kwrd"&gt;if&lt;/span&gt;(user == &lt;span class="kwrd"&gt;null&lt;/span&gt; || (user.Role != UserRole.Moderator &amp;amp;&amp;amp; user.Role != UserRole.Admin))
    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; HttpStatusCodeResult(403, &lt;span class="str"&gt;"You must be logged in as moderator or admin to be able to delete comments"&lt;/span&gt;);

  RavenSession.Delete(user);

  &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; HttpStatusCodeResult(204);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;</description><link>http://ayende.com/blog/154977/thou-shall-not-delete?key=a86334f4-49a8-4d6d-aca1-848c98741867</link><guid>http://ayende.com/blog/154977/thou-shall-not-delete?key=a86334f4-49a8-4d6d-aca1-848c98741867</guid><pubDate>Wed, 02 May 2012 09:00:00 GMT</pubDate></item><item><title>What is wrong here? Solution</title><description>&lt;p&gt;In my previous post, I showed the database schema and the UI and asked what was wrong with that. Before we move on, here is what I showed.&lt;/p&gt; &lt;p&gt;&lt;img alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/What-is-wrong-here_8F02/image_thumb_1.png"&gt;&lt;/p&gt; &lt;p&gt;&lt;img alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/What-is-wrong-here_8F02/image_thumb_3.png"&gt;&lt;/p&gt;  &lt;p&gt;If you looked carefully, you might have noticed that there are duplicate PO# and Tracking# in the UI. More than that, we somehow double charged the customer for shipping.&lt;/p&gt; &lt;p&gt;What is going on?&lt;/p&gt; &lt;p&gt;It is actually fairly obvious, when you think about it. Look at the schema, there isn’t actually &lt;em&gt;any&lt;/em&gt; association between the Tracking # and the PO #. In most orders, we have only 1 PO #, so it was easy to just add this information by just pulling it from the DB and adding a few columns. But when we got an order that has multiple POs… that is when all hell breaks lose.&lt;/p&gt; &lt;p&gt;This is a classic Cartesian Product problem.&lt;/p&gt; &lt;p&gt;The solution?&amp;nbsp; Actually model the UI to avoid suggesting that there is a relationship between the tracking and purchase orders, like this:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/What-is-wrong-here-solution_919F/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/What-is-wrong-here-solution_919F/image_thumb.png" width="611" height="892"&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://ayende.com/blog/153313/what-is-wrong-here-solution?key=4e108bbb-a95a-4e8e-9006-e300403e7f3d</link><guid>http://ayende.com/blog/153313/what-is-wrong-here-solution?key=4e108bbb-a95a-4e8e-9006-e300403e7f3d</guid><pubDate>Sun, 26 Feb 2012 10:00:00 GMT</pubDate></item><item><title>What is wrong here?</title><description>&lt;p&gt;This case, it isn’t code that I am going to show, rather, I am going to show the final UI and the database structure, and let you figure:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;What is wrong.&lt;/li&gt; &lt;li&gt;How to fix this.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Here is the database schema:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/What-is-wrong-here_8F02/image_4.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/What-is-wrong-here_8F02/image_thumb_1.png" width="449" height="497"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And here is the problem:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/What-is-wrong-here_8F02/image_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/What-is-wrong-here_8F02/image_thumb_3.png" width="611" height="892"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Hints, this used to work for a long time, and suddenly it doesn’t, and the customer is &lt;em&gt;pissed, &lt;/em&gt;annoyed and threatening to sue.&lt;/p&gt;</description><link>http://ayende.com/blog/153281/what-is-wrong-here?key=8b24b408-1be2-4d67-9945-5be9e2978949</link><guid>http://ayende.com/blog/153281/what-is-wrong-here?key=8b24b408-1be2-4d67-9945-5be9e2978949</guid><pubDate>Fri, 24 Feb 2012 10:00:00 GMT</pubDate></item><item><title>Ask Ayende: What about the QA env?</title><description>&lt;p&gt;&lt;a&gt;Matthew Bonig&lt;/a&gt; asks, with regards to &lt;a href="http://ayende.com/blog/152738/bug-hunt-what-made-this-blog-slow"&gt;a bug&lt;/a&gt; in RavenDB MVC Integration (RavenDB Profiler) that caused major slow down on this blog.: &lt;blockquote&gt; &lt;p&gt;I'd be very curious to know how this code got published to a production environment without getting caught. I would have thought this problem would have occurred in any testing environment as well as it did here. Ayende, can you comment on where the process broke down and how such an obvious bug was able to slip through?&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Well, the answer for that comes in two parts. The first part&amp;nbsp; is that no process broke down. We use our own assets for final testing of all our software, that means that whenever there is a stable RavenDB release pending (and sometimes just when we feel like it) we move our infrastructure to the latest and greatest. &lt;p&gt;&lt;em&gt;Why? &lt;/em&gt; &lt;p&gt;Because as hard as you try testing, you will never be able to catch everything. Production is the final test ground, and we have obvious incentives of trying to make sure that everything works.&amp;nbsp; It is dogfooding, basically. Except that if we get a lemon, that is a very public one. &lt;p&gt;It means that whenever we make a stable release, we can do that with high degree of confidence that everything is going to work, not just because all the tests are passing, but because our production systems had days to actually see if things are right. &lt;p&gt;The second part of this answer is that this is neither an obvious bug nor one that is easy to catch. Put simply, things &lt;em&gt;worked&lt;/em&gt;. There wasn’t even an infinite loop that would make it obvious that something is wrong, it is just that there was a lot of network traffic that you would notice only if you either had a tracer running, or were trying to figure out why the browser was suddenly so busy. &lt;p&gt;Here is a challenge, try to devise some form of an automated test that would catch something like this error, but do so without actually testing for &lt;em&gt;this specific issue&lt;/em&gt;. After all, it is unlikely that someone would have written a test for this unless they run into the error in the first place. So I would be really interested in seeing what sort of automated approaches would have caught that.&lt;/p&gt;</description><link>http://ayende.com/blog/153825/ask-ayende-what-about-the-qa-env?key=6d32f8c5-ef61-45ef-90b3-edb437ee2333</link><guid>http://ayende.com/blog/153825/ask-ayende-what-about-the-qa-env?key=6d32f8c5-ef61-45ef-90b3-edb437ee2333</guid><pubDate>Tue, 31 Jan 2012 07:33:00 GMT</pubDate></item><item><title>Bug Hunt: What made this blog slow?</title><description>&lt;p&gt;A while ago the blog start taking 100% CPU on the client machines. Obviously we were doing something very wrong there, but what exactly was it?&lt;/p&gt; &lt;p&gt;We tracked down the problem to the following code:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Bug-Hunt-What-made-this-blog-slow_FB72/image_thumb_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image_thumb" border="0" alt="image_thumb" src="http://ayende.com/blog/Images/Windows-Live-Writer/Bug-Hunt-What-made-this-blog-slow_FB72/image_thumb_thumb.png" width="587" height="224"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Bug-Hunt-What-made-this-blog-slow_FB72/image_thumb%5B1%5D_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image_thumb[1]" border="0" alt="image_thumb[1]" src="http://ayende.com/blog/Images/Windows-Live-Writer/Bug-Hunt-What-made-this-blog-slow_FB72/image_thumb%5B1%5D_thumb.png" width="392" height="113"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;As you can probably guess, the problem is that we have what is effective an infinite loop. On any Ajax request, we will generate a new Ajax request. And that applies to &lt;em&gt;our own requests as well&lt;/em&gt;.&lt;/p&gt; &lt;p&gt;The fix was pretty obvious when we figured out what was going on, but until then…&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Bug-Hunt-What-made-this-blog-slow_FB72/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Bug-Hunt-What-made-this-blog-slow_FB72/image_thumb_3.png" width="538" height="142"&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://ayende.com/blog/152738/bug-hunt-what-made-this-blog-slow?key=a6c5d835-aac9-4e13-bfcf-df39626ed5dc</link><guid>http://ayende.com/blog/152738/bug-hunt-what-made-this-blog-slow?key=a6c5d835-aac9-4e13-bfcf-df39626ed5dc</guid><pubDate>Mon, 30 Jan 2012 10:00:00 GMT</pubDate></item><item><title>Bug Hunt: What made this blog slow?</title><description>&lt;p&gt;A while ago the blog start taking 100% CPU on the client machines. Obviously we were doing something very wrong there, but what exactly was it?&lt;/p&gt; &lt;p&gt;We track down the problem to the following code, can you figure out what the problem?&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Bug-Hunt-What-made-this-blog-slow_FB38/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Bug-Hunt-What-made-this-blog-slow_FB38/image_thumb.png" width="587" height="224"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Bug-Hunt-What-made-this-blog-slow_FB38/image_4.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Bug-Hunt-What-made-this-blog-slow_FB38/image_thumb_1.png" width="392" height="113"&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://ayende.com/blog/152737/bug-hunt-what-made-this-blog-slow?key=9aca2476-1a93-4c84-9284-020ee76f79a5</link><guid>http://ayende.com/blog/152737/bug-hunt-what-made-this-blog-slow?key=9aca2476-1a93-4c84-9284-020ee76f79a5</guid><pubDate>Fri, 27 Jan 2012 10:00:00 GMT</pubDate></item><item><title>What is up with all those 404?</title><description>&lt;p&gt;Recently I had a spate of posts showing up, and then reporting 404. The actual reason behind that was that the server and the database disagreed with one another with regards to the timezone of the post (one was using UTC, the other local). Sorry for the trouble, and this shouldn’t happen any longer.&lt;/p&gt;</description><link>http://ayende.com/blog/152609/what-is-up-with-all-those-404?key=84e3baa6-c032-4e33-88ab-7b9745f29bfc</link><guid>http://ayende.com/blog/152609/what-is-up-with-all-those-404?key=84e3baa6-c032-4e33-88ab-7b9745f29bfc</guid><pubDate>Thu, 22 Dec 2011 20:00:00 GMT</pubDate></item><item><title>Mixing Integrated Authentication and Anonymous Authentication with PreAuthenticated = true doesn&amp;rsquo;t work</title><description>&lt;p&gt;This &lt;a href="http://stackoverflow.com/questions/1547661/ie-iis-integrated-authentication-problem"&gt;StackOverflow question&lt;/a&gt; indicate that it is half a bug and half a feature, but that it sure as hell looks like a bug to me.&lt;/p&gt; &lt;p&gt;Let us assume that we have a couple of endpoints in our application, called &lt;strong&gt;&lt;a href="http://localhost:8080/secure"&gt;http://localhost:8080/secure&lt;/a&gt; &lt;/strong&gt; and &lt;a href="http://localhost:8080/public"&gt;&lt;strong&gt;http://localhost:8080/public&lt;/strong&gt;&lt;/a&gt;. As you can imagine, the secure endpoint is… well, secure, and requires authentication. The public endpoint does not.&lt;/p&gt; &lt;p&gt;We want to optimize the number of request we make, so we specify PreAuthenticated = true; And that is where all hell break lose. &lt;/p&gt; &lt;p&gt;The problem is that it appears that when using request with entity body (in other words, PUT / POST) with PreAuthenticate = true, the .NET framework will issue a PUT / POST request with &lt;em&gt;empty body&lt;/em&gt; to the server. Presumably to get the 401 authentication information. At that point, if the endpoint that it happened to have reached is public, it will be accepted as a standard request, and processing will be tried. The problem here is that it has an &lt;em&gt;empty body&lt;/em&gt;, so that has a very strong likelihood of failing.&lt;/p&gt; &lt;p&gt;This error cost me a day and a half or so. Here is the full repro:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main()
{
    &lt;span class="kwrd"&gt;new&lt;/span&gt; Thread(Server)
    {
        IsBackground = &lt;span class="kwrd"&gt;true&lt;/span&gt;
    }.Start();

    Thread.Sleep(500); &lt;span class="rem"&gt;// let the server start&lt;/span&gt;

    &lt;span class="kwrd"&gt;bool&lt;/span&gt; secure = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
    &lt;span class="kwrd"&gt;while&lt;/span&gt; (&lt;span class="kwrd"&gt;true&lt;/span&gt;)
    {
        secure = !secure;
        Console.Write(&lt;span class="str"&gt;"Sending: "&lt;/span&gt;);
        var str = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;(&lt;span class="str"&gt;'a'&lt;/span&gt;, 621);
        var req = WebRequest.Create(secure ? &lt;span class="str"&gt;"http://localhost:8080/secure"&lt;/span&gt; : &lt;span class="str"&gt;"http://localhost:8080/public"&lt;/span&gt;);
        req.Method = &lt;span class="str"&gt;"PUT"&lt;/span&gt;;

        var byteCount = Encoding.UTF8.GetByteCount(str);
        req.UseDefaultCredentials = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
        req.Credentials = CredentialCache.DefaultCredentials;
        req.PreAuthenticate = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
        req.ContentLength = byteCount;

        &lt;span class="kwrd"&gt;using&lt;/span&gt;(var stream = req.GetRequestStream())
        {
            var bytes = Encoding.UTF8.GetBytes(str);
            stream.Write(bytes, 0, bytes.Length);
            stream.Flush();
        }

        req.GetResponse().Close();

    }

}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;And the server code:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Server()
{
    var listener = &lt;span class="kwrd"&gt;new&lt;/span&gt; HttpListener();
    listener.Prefixes.Add(&lt;span class="str"&gt;"http://+:8080/"&lt;/span&gt;);
    listener.AuthenticationSchemes = AuthenticationSchemes.IntegratedWindowsAuthentication | AuthenticationSchemes.Anonymous;
    listener.AuthenticationSchemeSelectorDelegate = request =&amp;gt;
    {

        &lt;span class="kwrd"&gt;return&lt;/span&gt; request.RawUrl.Contains(&lt;span class="str"&gt;"public"&lt;/span&gt;) ? AuthenticationSchemes.Anonymous : AuthenticationSchemes.IntegratedWindowsAuthentication;
    };

    listener.Start();

    &lt;span class="kwrd"&gt;while&lt;/span&gt; (&lt;span class="kwrd"&gt;true&lt;/span&gt;)
    {
        var context = listener.GetContext();
        Console.WriteLine(context.User != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? context.User.Identity.Name : &lt;span class="str"&gt;"Anonymous"&lt;/span&gt;);
        &lt;span class="kwrd"&gt;using&lt;/span&gt;(var reader = &lt;span class="kwrd"&gt;new&lt;/span&gt; StreamReader(context.Request.InputStream))
        {
            var readToEnd = reader.ReadToEnd();
            &lt;span class="kwrd"&gt;if&lt;/span&gt;(&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(readToEnd))
            {
                Console.WriteLine(&lt;span class="str"&gt;"WTF?!"&lt;/span&gt;);
                Environment.Exit(1);
            }
        }

        context.Response.StatusCode = 200;
        context.Response.Close();
    }
}
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;If we remove pre authenticate is set to false, everything works, but then we have twice as many requests. The annoying thing is that if it would be trying to authenticate to a public endpoint, nothing would happen, &lt;em&gt;if it were sending the bloody entity body along as well&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;This is &lt;em&gt;quite &lt;/em&gt;annoying.&lt;/p&gt;</description><link>http://ayende.com/blog/149505/mixing-integrated-authentication-and-anonymous-authentication-with-preauthenticated-true-doesnrsquo-t-work?key=0604af72-398f-4bb3-a504-e576207acbb8</link><guid>http://ayende.com/blog/149505/mixing-integrated-authentication-and-anonymous-authentication-with-preauthenticated-true-doesnrsquo-t-work?key=0604af72-398f-4bb3-a504-e576207acbb8</guid><pubDate>Thu, 22 Dec 2011 10:00:00 GMT</pubDate></item><item><title>Dynamic resolution rules joy</title><description>&lt;p&gt;In the following code, what do you believe the output should be?&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; Program
{
    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)
    {
        dynamic stupid = &lt;span class="kwrd"&gt;new&lt;/span&gt; Stupid{Age = 3};

        Console.WriteLine(stupid.Age);
    }
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Stupid : DynamicObject
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Age { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; TryGetMember(GetMemberBinder binder, &lt;span class="kwrd"&gt;out&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; result)
    {
        result = 1;
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;
    }
}
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;Argh!&lt;/p&gt;
&lt;p&gt;The default is to use the actual type members, and then fall back to the dynamic behavior. Whereas I would expect it to first check the dynamic behavior and then fall back to the actual members if it can’t find dynamic stuff.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Quite&lt;/em&gt; annoying.&lt;/p&gt;</description><link>http://ayende.com/blog/119809/dynamic-resolution-rules-joy?key=d1416f3b-99af-410e-9345-d2b368a3c961</link><guid>http://ayende.com/blog/119809/dynamic-resolution-rules-joy?key=d1416f3b-99af-410e-9345-d2b368a3c961</guid><pubDate>Fri, 21 Oct 2011 10:00:00 GMT</pubDate></item><item><title>What is wrong with this code?</title><description>&lt;p&gt;Calling the Compare method will (sometimes) crash your entire application in a very rude fashion, why?&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Compare(&lt;span class="kwrd"&gt;byte&lt;/span&gt;[] b1, &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] b2)
  {
    IntPtr retval = memcmp(b1, b2, &lt;span class="kwrd"&gt;new&lt;/span&gt; IntPtr(b1.Length));
    &lt;span class="kwrd"&gt;return&lt;/span&gt; retval == IntPtr.Zero;
  }
 
  [DllImport(&lt;span class="str"&gt;"msvcrt.dll"&lt;/span&gt;)]
  &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;extern&lt;/span&gt; IntPtr memcmp(&lt;span class="kwrd"&gt;byte&lt;/span&gt;[] b1, &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] b2, IntPtr count);&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;In fact, there are actually two different problems that I can see here. The easy one would consistently crash, the hard one would usually pass, but sometime crash you in an apparently random ways.&lt;/p&gt;</description><link>http://ayende.com/blog/118785/what-is-wrong-with-this-code?key=13a4eb09-f730-4835-8adf-987cac817e66</link><guid>http://ayende.com/blog/118785/what-is-wrong-with-this-code?key=13a4eb09-f730-4835-8adf-987cac817e66</guid><pubDate>Thu, 13 Oct 2011 10:00:00 GMT</pubDate></item><item><title>Rant: Who thought THIS was a good idea?!</title><description>&lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Rant-Who-thought-THIS-was-a-good-idea_B844/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Rant-Who-thought-THIS-was-a-good-idea_B844/image_thumb.png" width="747" height="343"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;I means, seriously!&lt;/p&gt; &lt;p&gt;Even this is better:&lt;/p&gt; &lt;p&gt;&lt;img src="http://cache.automation.siemens.com/dnl/TE1MDg1AAAA_22633773_FAQ/22633773_OS_Error_5.jpg"&gt;&lt;/p&gt;</description><link>http://ayende.com/blog/87041/rant-who-thought-this-was-a-good-idea?key=c40847cc-0f88-4bc0-93de-56a8136cf65b</link><guid>http://ayende.com/blog/87041/rant-who-thought-this-was-a-good-idea?key=c40847cc-0f88-4bc0-93de-56a8136cf65b</guid><pubDate>Thu, 08 Sep 2011 09:00:00 GMT</pubDate></item><item><title>Twitter doesn&amp;rsquo;t like my identity</title><description>&lt;p&gt;Recently I noticed that a very important feature in twitter website is broken for me. I can’t follow the entire conversation any longer, which drive me crazy.&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Twitter-doesnt-like-my-identity_B1BC/image_4.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Twitter-doesnt-like-my-identity_B1BC/image_thumb_1.png" width="1118" height="167"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;It didn’t take me long to figure out what the actual issue is:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Twitter-doesnt-like-my-identity_B1BC/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Twitter-doesnt-like-my-identity_B1BC/image_thumb.png" width="559" height="523"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;It appears that even though I am logged in, some parts of twitter doesn’t like this.&lt;/p&gt; &lt;p&gt;I then thought that this has something to do with chrome, so I used the incognito mode to try it:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Twitter-doesnt-like-my-identity_B1BC/image_6.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Twitter-doesnt-like-my-identity_B1BC/image_thumb_2.png" width="1095" height="319"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;It works!&lt;/p&gt; &lt;p&gt;I logged out and in again, nada. I cleared all browser history and restarted chrome, nada.&lt;/p&gt; &lt;p&gt;I uninstalled chrome (selecting delete all browsing history) and re-installed, and now it is working.&lt;/p&gt; &lt;p&gt;No idea why, and I don’t like the heavy handed approach, but at least now I got my twitter tracking back.&lt;/p&gt;</description><link>http://ayende.com/blog/86017/twitter-doesnrsquo-t-like-my-identity?key=e518196f-89fa-4909-8a66-fd0f81687553</link><guid>http://ayende.com/blog/86017/twitter-doesnrsquo-t-like-my-identity?key=e518196f-89fa-4909-8a66-fd0f81687553</guid><pubDate>Wed, 07 Sep 2011 09:00:00 GMT</pubDate></item><item><title>Debugging Security Exceptions</title><description>&lt;p&gt;One of the horrible things about SecurityException is just how little information you are given.&lt;/p&gt; &lt;p&gt;For example, let us take a look at:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Debugging-Security-Exceptions_A0E2/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Debugging-Security-Exceptions_A0E2/image_thumb.png" width="991" height="381"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Yes, that is informative. The real problem is that most security analysis is done at the method level, which means that _something_ in this method caused this problem. Which meant that in order to debug this, I have to change my code to be like this:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Debugging-Security-Exceptions_A0E2/image_4.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Debugging-Security-Exceptions_A0E2/image_thumb_1.png" width="530" height="208"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Which gives me this:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Debugging-Security-Exceptions_A0E2/image_6.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Debugging-Security-Exceptions_A0E2/image_thumb_2.png" width="988" height="79"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Just to point out, the first, second, etc are purely artificial method names, meant just to give me some idea about the problem areas for this purpose only.&lt;/p&gt; &lt;p&gt;Then we need to go into the code in the First method and figure out what the problem is there, and so on, and so forth.&lt;/p&gt; &lt;p&gt;Annoying, and I wish that I knew of a better way.&lt;/p&gt;</description><link>http://ayende.com/blog/73729/debugging-security-exceptions?key=ec026b55-9386-432d-9682-b544f22ad04c</link><guid>http://ayende.com/blog/73729/debugging-security-exceptions?key=ec026b55-9386-432d-9682-b544f22ad04c</guid><pubDate>Mon, 29 Aug 2011 09:00:00 GMT</pubDate></item><item><title>High memory usage with WCF Discovery</title><description>&lt;p&gt;Yes, I know that this is basically saying that select is broken, but I am seeing some very strange stuff here. The code in question is this:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 15; i++)
{
    var discoveryClient = &lt;span class="kwrd"&gt;new&lt;/span&gt; DiscoveryClient(&lt;span class="kwrd"&gt;new&lt;/span&gt; UdpDiscoveryEndpoint());
    var findCriteria = &lt;span class="kwrd"&gt;new&lt;/span&gt; FindCriteria(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(IDiscoverableService))
    {
        Duration = TimeSpan.FromSeconds(1)
    };
    discoveryClient.Find(findCriteria);
    discoveryClient.Close();
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;The full repro can be &lt;a href="https://gist.github.com/1098963"&gt;found here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The problem is, put simply, that before this code, the working set is:&amp;nbsp; Working Set: 57,640 kb, after this have executed, it is 90,288 kb.&lt;/p&gt;
&lt;p&gt;I went over the code with a fine tooth comb, but I don’t really see where all of this memory have gone. &lt;/p&gt;
&lt;p&gt;The actual memory reported by GC.GetTotalMemory does go down after the cleanup, so I guess it could be that .NET isn’t releasing the memory back to the OS, but it still worries me somewhat.&lt;/p&gt;
&lt;p&gt;I tried it with higher numbers for the loop, and it seems like eventually it settles down on some number and doesn’t grow from there. My main problem is what happens when you start doing async stuff. Let us take a look here:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; count = 150;
var countdown = &lt;span class="kwrd"&gt;new&lt;/span&gt; CountdownEvent(count);

&lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; count; i++)
{
    var discoveryClient = &lt;span class="kwrd"&gt;new&lt;/span&gt; DiscoveryClient(&lt;span class="kwrd"&gt;new&lt;/span&gt; UdpDiscoveryEndpoint());
    var findCriteria = &lt;span class="kwrd"&gt;new&lt;/span&gt; FindCriteria(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(IDiscoverableService))
    {
    };
    discoveryClient.FindProgressChanged += (sender, eventArgs) =&amp;gt; {  }; &lt;span class="rem"&gt;// do nothing&lt;/span&gt;
    discoveryClient.FindCompleted += (sender, eventArgs) =&amp;gt;
    {
        countdown.AddCount();
        discoveryClient.Close();
        PrintMemory(&lt;span class="str"&gt;"Complete: "&lt;/span&gt;);
    };
    discoveryClient.FindAsync(findCriteria);
}

countdown.Wait();&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;At peek, I am seeing 600 MB (!) of memory used. Note that we are now using the default duration of 20 seconds, and it seems that DiscoveryClient is very heavy on memory.&lt;/p&gt;
&lt;p&gt;If you know how, can you take a look at the code and tell me that I am crazy?&lt;/p&gt;</description><link>http://ayende.com/blog/67585/high-memory-usage-with-wcf-discovery?key=3615eeed-6315-4329-be7e-f569630b40f5</link><guid>http://ayende.com/blog/67585/high-memory-usage-with-wcf-discovery?key=3615eeed-6315-4329-be7e-f569630b40f5</guid><pubDate>Fri, 22 Jul 2011 07:20:00 GMT</pubDate></item><item><title>Where are your debug hooks?</title><description>&lt;p&gt;One of the most important things that I learned about working with software is that you &lt;em&gt;have&lt;/em&gt; to design, from the get go, the debug ability of the system. This is important, because by default, here is how the your system reports its state:&lt;/p&gt; &lt;p&gt;&lt;img src="http://chrisstephenson.typepad.com/photos/uncategorized/2007/03/31/black_box.jpg"&gt;&lt;/p&gt; &lt;p&gt;To make things worse, in many cases, we are talking about things that are &lt;em&gt;really&lt;/em&gt; hard to figure out. With Rhino Service Bus, I had started, from day one, to add a &lt;em&gt;lot&lt;/em&gt; of debug logs, we had the idea of the logging endpoint, error messages went to the error queue along with the error that they generated, etc.&lt;/p&gt; &lt;p&gt;With NHibernate, it took me three days after starting to build NH Prof to figure out that NH Prof was a great tool to use when &lt;em&gt;working on NHibernate itself.&amp;nbsp; &lt;/em&gt;With NH Prof, the actual file format that we used is an event stream, which is logged locally. Which means that the process of opening a saved file and listening to a running application is &lt;em&gt;the same&lt;/em&gt;. That means that you can send me you File &amp;gt; Save output, and I can simulate locally the exact conditions that led to whatever problems you had.&lt;/p&gt; &lt;p&gt;As software becomes more and more complex, threading is involved, complex scenarios are introduced, multiple actors involved and more and more data is streaming in. The old patterns of debugging through a problem become less and less relevant. To put it simply, it is less and less &lt;em&gt;possible&lt;/em&gt; to easily reconstruct a problem in most scenarios, at least, it is very hard to do from the information given.&lt;/p&gt; &lt;p&gt;Last week I started to add support for profiling RavenDB. The intent was mostly to allow us to build better integration with web applications, but during the process of investigating a &lt;em&gt;very&lt;/em&gt; nasty bug, I figured out that I could use this profiling information to figure out what is going on. I did, and seeing the information, it was immediately obvious what was wrong.&lt;/p&gt; &lt;p&gt;I decided that I might was well go the whole hog there and introduced this:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Where-is-your-debug-hooks_9FA1/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Where-is-your-debug-hooks_9FA1/image_thumb.png" width="769" height="739"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;No, it isn’t RavenDB Profiler (not yet), but it is a debug visualizer that you can use to look at the raw requests. It is a bit more than just a Fiddler clone, too, since it has awareness of things like RavenDB sessions, caching, aggressive caching, etc. &lt;/p&gt; &lt;p&gt;In the short time that this API is available, it has already help resolve at least two separate (and very hard to figure out) bugs.&lt;/p&gt;
&lt;p&gt;I learned two things from the experience:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Having the debug hooks is &lt;em&gt;critically important, &lt;/em&gt;because it means that you can access that information at need.&lt;/li&gt;
&lt;li&gt;Just having the debug hooks is not enough, you have to provide a good way for them to be &lt;em&gt;used&lt;/em&gt;.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;In this case, it is a debugger visualizer, but we will have additional ways to expose this information to the users.&lt;/p&gt;</description><link>http://ayende.com/blog/21505/where-are-your-debug-hooks?key=a1f93d04-9e22-4746-aad7-7e4df40d4d30</link><guid>http://ayende.com/blog/21505/where-are-your-debug-hooks?key=a1f93d04-9e22-4746-aad7-7e4df40d4d30</guid><pubDate>Thu, 23 Jun 2011 09:00:00 GMT</pubDate></item></channel></rss>
