﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Ori Peleg commented on Challenge: Find the bug</title><description>Awesome, especially for the "Think C++" hint. I wonder why we consider exception-safety differently when we're not in C++.
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment32</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment32</guid><pubDate>Sun, 11 Jul 2010 10:48:46 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug</title><description>Matthew,
  
Ding, ding ding!
  
You got it.
  
The dispose is actually never called, because we aren't completing the ctor.
  
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment31</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment31</guid><pubDate>Wed, 30 Jun 2010 16:02:57 GMT</pubDate></item><item><title>Richard Dingwall commented on Challenge: Find the bug</title><description>Doing file IO in a ctor is a shooting offense. Wouldn't be surprised if that is a factor.
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment30</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment30</guid><pubDate>Wed, 30 Jun 2010 11:46:57 GMT</pubDate></item><item><title>Matthew Wills commented on Challenge: Find the bug</title><description>Well, assuming you are using a using block around your use of TransactionStorage, I suspect the writer will stay alive and thus lock the DB. I suspect GC would get it *eventually* – I haven't tested and thus don’t know for sure.
  
  
You likely should change your Dispose method to handle partially constructed objects (ie don’t assume everything is initialized correctly) and then call the Dispose from a catch block in your constructor.
  
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment29</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment29</guid><pubDate>Wed, 30 Jun 2010 11:38:41 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug</title><description>Matthew,
  
Yes, you are right, what is the result?
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment28</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment28</guid><pubDate>Wed, 30 Jun 2010 11:33:38 GMT</pubDate></item><item><title>Matthew Wills commented on Challenge: Find the bug</title><description>You are throwing an exception from a constructor. So I suppose you could have a partially constructed object - not sure what impact this would have on the disposal of the writer, for instance.
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment27</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment27</guid><pubDate>Wed, 30 Jun 2010 11:12:27 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug</title><description>Gerard,
  
Not it either
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment26</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment26</guid><pubDate>Wed, 30 Jun 2010 11:08:02 GMT</pubDate></item><item><title>Gerard Kappen commented on Challenge: Find the bug</title><description>I'm not sure if you're aiming for some sort of backward compatibility in your storage file, but if so, I would assume you'd rather compare the version as
  
  
if (version &gt; Version)
  
 throw ... 
  
  
  
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment25</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment25</guid><pubDate>Wed, 30 Jun 2010 10:57:17 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug</title><description>@Everyone,
  
Here is a big hint, think C++
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment24</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment24</guid><pubDate>Wed, 30 Jun 2010 10:55:20 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug</title><description>Matthew,
  
Good catch, but that still isn't it
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment23</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment23</guid><pubDate>Wed, 30 Jun 2010 10:55:00 GMT</pubDate></item><item><title>Matthew Wills commented on Challenge: Find the bug</title><description>If path wasn't an existing directory but was an existing FILE then the CreateDirectory would throw IOException.
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment22</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment22</guid><pubDate>Wed, 30 Jun 2010 10:51:53 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug</title><description>Ryan,
  
That means that you can delete the file, which is important for some scenarios (cleanup, mostly).
  
That is not a bug
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment21</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment21</guid><pubDate>Wed, 30 Jun 2010 10:12:30 GMT</pubDate></item><item><title>Ryan Heath commented on Challenge: Find the bug</title><description>Why is FileShare.Delete allowed? Writing to a file that is allowed to be deleted, that looks like a bug to me ...
  
  
// Ryan
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment20</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment20</guid><pubDate>Wed, 30 Jun 2010 10:05:52 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug</title><description>Mattia,
  
I don't worry about that, I'll get the appropriate error then.
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment19</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment19</guid><pubDate>Wed, 30 Jun 2010 08:23:17 GMT</pubDate></item><item><title>Mattia commented on Challenge: Find the bug</title><description>You don't check if you have enough space on disk before creating file. This may result in a IOException if the disk is full.
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment18</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment18</guid><pubDate>Wed, 30 Jun 2010 07:52:40 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug</title><description>David,
  
No, that is okay, we assume that len = 0 is always okay.
  
  
  
Matt,
  
Ignore race conditions, as other have pointed out, it will work, but the problem isn't with a race condition.
  
  
Tim,
  
No, bad permissions would cause it to crash with an expected error.
  
  
Andy,
  
Actually, that is okay, I always want to read from the file. CreateFromScratch just set things up for me.
  
  
Stephane,
  
The writer is close is the Dispose() method.
  
  
Chris,
  
Ignore any race conditions, they aren't required to show the bug.
  
  
Steve,
  
That is not a problem, only one instance of RavenDB can own a file at a given time.
  
  
Simon,
  
Thanks, that is expected and not what I meant.
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment17</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment17</guid><pubDate>Wed, 30 Jun 2010 06:47:07 GMT</pubDate></item><item><title>Geert Baeyaert commented on Challenge: Find the bug</title><description>The race condition is not between the first two lines, but between creating the directory and creating the file.
  
  
Directory.CreateDirectory throws an IOException when the directory is read-only or not empty. 
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment16</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment16</guid><pubDate>Wed, 30 Jun 2010 06:14:31 GMT</pubDate></item><item><title>Martin commented on Challenge: Find the bug</title><description>If the path parameter is a drive letter (eg "C:") then Path.Combine won't create a valid path. You'll get "C:storage.raven" instead of "C:\storage.raven".
  
(unless of course you're appending the slash in the caller.)
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment15</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment15</guid><pubDate>Wed, 30 Jun 2010 05:48:46 GMT</pubDate></item><item><title>Simon Labrecque commented on Challenge: Find the bug</title><description>Not sure if you'consider it a bug since you kinda expect an exception anyway, but
  
  
 if (new Guid(binaryReader.ReadBytes(16)) != HeaderSignatureGuid)
  
  
will generate an ArgumentException when the file exists but is not at least 16 bytes long.
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment14</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment14</guid><pubDate>Wed, 30 Jun 2010 00:50:54 GMT</pubDate></item><item><title>Steve Py commented on Challenge: Find the bug</title><description>I suspect the writer is module level and left open so that data can be streamed to file. It has read-level sharing.
  
  
the check on writer.Length == 0 doesn't sit right with me. It looks like you want to check to see if the file was newly created then call the CreateFromScratch().
  
  
I'd have elected for:
  
storageFile = Path.Combine...
  
isNewDatabase = File.Exists(storageFile);
  
writer = ...
  
  
if (isNewDatabase)
  
    CreateFromScratch()
  
  
But that's just semantics, I don't think that's the cause of any bug...
  
  
Two instances of the same application implementing Raven DB could be a problem if started up around the same time.
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment13</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment13</guid><pubDate>Tue, 29 Jun 2010 22:56:56 GMT</pubDate></item><item><title>Rik Hemsley commented on Challenge: Find the bug</title><description>I've parsed this a few times and can't see the bug. I write similar code often so I'll be checking back to see what you reveal as the answer in case I've fallen into the same trap!
  
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment12</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment12</guid><pubDate>Tue, 29 Jun 2010 22:34:26 GMT</pubDate></item><item><title>Chris C commented on Challenge: Find the bug</title><description>If the file is deleted whilst the writer is open then OpenReader will fail (assuming open reader is creating a new file stream).
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment11</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment11</guid><pubDate>Tue, 29 Jun 2010 22:29:46 GMT</pubDate></item><item><title>Stephane commented on Challenge: Find the bug</title><description>Where do you close the writer?
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment10</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment10</guid><pubDate>Tue, 29 Jun 2010 21:34:18 GMT</pubDate></item><item><title>Louis Hau&amp;#223;knecht commented on Challenge: Find the bug</title><description>@Ramon Smits,
  
  
that's Ayende's coding style. 
  
  
I like it.
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment9</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment9</guid><pubDate>Tue, 29 Jun 2010 20:25:12 GMT</pubDate></item><item><title>James Curran commented on Challenge: Find the bug</title><description>@matt,
  
  
nope.  The .Net CreateDirectory silently NOPs if the directory is already present (the if() is superfluous).
  
  
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment8</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment8</guid><pubDate>Tue, 29 Jun 2010 20:17:18 GMT</pubDate></item><item><title>Andy K commented on Challenge: Find the bug</title><description>Not knowing what CreateFromScratch does I would guess that you don't want to TryReadingFromExistingFile when isNewDatabase.
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment7</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment7</guid><pubDate>Tue, 29 Jun 2010 20:06:18 GMT</pubDate></item><item><title>Ramon Smits commented on Challenge: Find the bug</title><description>Why the weird ==false check and not using if(! construct? THen again, AFAIK the Directory.Create will do nothing when it already exists. So the check is useless.
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment6</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment6</guid><pubDate>Tue, 29 Jun 2010 20:02:56 GMT</pubDate></item><item><title>Tim Schwallie commented on Challenge: Find the bug</title><description>Are the permissions to the Directory ok?
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment5</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment5</guid><pubDate>Tue, 29 Jun 2010 16:38:44 GMT</pubDate></item><item><title>matt commented on Challenge: Find the bug</title><description>race condition in the 1st two lines between checking for the existence of the directory and creating it.
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment4</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment4</guid><pubDate>Tue, 29 Jun 2010 16:02:55 GMT</pubDate></item><item><title>David Thibault commented on Challenge: Find the bug</title><description>Check the length of the reader before validating the signature ?
</description><link>http://ayende.com/4549/challenge-find-the-bug#comment3</link><guid>http://ayende.com/4549/challenge-find-the-bug#comment3</guid><pubDate>Tue, 29 Jun 2010 15:48:20 GMT</pubDate></item></channel></rss>