﻿<?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>Stephen commented on Challenge: Find the bug fixes</title><description>Ah yes, completely misread the code.. I always assume Session when I see default property access with httpcontexts. 
  
  
Apologies!
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment57</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment57</guid><pubDate>Wed, 19 Aug 2009 20:50:00 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug fixes</title><description>Stephen,
  
I am not putting it in the http sesson, I am putting it on the http _request_
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment56</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment56</guid><pubDate>Wed, 19 Aug 2009 20:11:49 GMT</pubDate></item><item><title>Stephen commented on Challenge: Find the bug fixes</title><description>One thing I was wondering ayende, was why you chose to store the nhibernate session in in the http session, couldn't you just have an instance variable, and assign to it on begin request and dispose of it on end request. I'm sure IIS ensures that a given HttpApplication can only handle one request at a time (sounds obvious but async handlers could mean this isn't so).. is it purely so you can use the static helper property to find the session?
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment55</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment55</guid><pubDate>Wed, 19 Aug 2009 19:39:33 GMT</pubDate></item><item><title>Stephen commented on Challenge: Find the bug fixes</title><description>@Niclas, this isn't specifically an mvc thing.. whatever requests you map IIS to handle (and with IIS7 this is even more so) will get sessions.. you would potentially filter by the handler type, not the extension which is unreliable.. an easier system which has other benefits is to move such static content onto another 'dump' domain, so you can cut the request / response down to an absolute min.
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment54</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment54</guid><pubDate>Mon, 17 Aug 2009 14:21:39 GMT</pubDate></item><item><title>Niclas Pehrsson commented on Challenge: Find the bug fixes</title><description>I seeing one issue more if you will use asp.net mvc BeginRequest will be called when you getting .css, jpeg.... files. And the application will open one session for each image or style file loaded.
  
  
It would be smart to only open it for aspx and other file extensions which will use nhibernate.
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment53</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment53</guid><pubDate>Sun, 16 Aug 2009 20:32:27 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug fixes</title><description>Stephen,
  
Yep!
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment52</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment52</guid><pubDate>Sat, 08 Aug 2009 13:33:40 GMT</pubDate></item><item><title>zihotki commented on Challenge: Find the bug fixes</title><description>And also you are using CurrentSession.Dispose() instead of CurrentSession.Close() because dispose method contains logic for logging of a session disposal. If you use Close method at the end of request information about session disposal will be logged only on run of GC. So the statistics will be wrong.
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment51</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment51</guid><pubDate>Sat, 08 Aug 2009 00:42:45 GMT</pubDate></item><item><title>zihotki commented on Challenge: Find the bug fixes</title><description>You are using HttpContext.Current instead of [ThreadStatic] ISession property - this will prevent from various bugs that related to IHttpAsyncHandler.
  
Event handlers added in ctor will be fired before handlers registered via Global.asax (Application_BeginRequest method, Application_EndRequest and so on) and before handlers of modules. And, as I think, this is the only reason why you used this approach.
  
This is all I can see from this code at the moment.
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment50</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment50</guid><pubDate>Fri, 07 Aug 2009 22:04:20 GMT</pubDate></item><item><title>ernest commented on Challenge: Find the bug fixes</title><description>ASP.NET uses a pool of HttpApplication instances, however Application_Start() method is called only on one of them. So when you bind events in the Application_Start() that the only one will have wired events and the others won't have wired events.
  
That is why you must use Global ctor.
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment49</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment49</guid><pubDate>Fri, 07 Aug 2009 21:07:31 GMT</pubDate></item><item><title>Mike Brown commented on Challenge: Find the bug fixes</title><description>Request isn't available for App_Start in IIS7
  
Also, you have a potential race condition under app_start if multiple requests come in. I'd assume however that IIS serializes/queues further requests until app_start completes. IF it doesn't though...none of the requests that came before App_Start completed will have the SessionFactory initialized.
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment48</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment48</guid><pubDate>Fri, 07 Aug 2009 17:04:23 GMT</pubDate></item><item><title>Stephen commented on Challenge: Find the bug fixes</title><description>OK, so.. is it that when running in classic mode (or IIS 6 and under), Application_Start will cause an exception only on the first request, but the next requests will all run and have no session factory (confusing to debug).. and the static initialization will throw every time a request tries to fire, thus making it easier to see what went wrong.
  
  
(Note that I think IIS7's default integrated mode now ensures the same for app_start).
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment47</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment47</guid><pubDate>Fri, 07 Aug 2009 15:09:37 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug fixes</title><description>Tuna,
  
Opps!
  
protected void Global is a typo ;-) Fixed
  
And yep, the event wiring must happen for every instance of http app.
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment46</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment46</guid><pubDate>Fri, 07 Aug 2009 14:57:00 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug fixes</title><description>Peter,
  
NotImplementedException is not subtle
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment45</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment45</guid><pubDate>Fri, 07 Aug 2009 14:55:21 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug fixes</title><description>Stephen,
  
Silently failing is the key, but static init will NOT silently fail
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment44</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment44</guid><pubDate>Fri, 07 Aug 2009 14:54:02 GMT</pubDate></item><item><title>gunteman commented on Challenge: Find the bug fixes</title><description>No, the session factory is only created once.
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment43</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment43</guid><pubDate>Fri, 07 Aug 2009 14:20:27 GMT</pubDate></item><item><title>Shyam commented on Challenge: Find the bug fixes</title><description>I think the "bug" that I can spot, is that you are creating a session factory each time there is a webrequest rather than caching up the session factory in a static reference and checking to see if ts null or not.
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment42</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment42</guid><pubDate>Fri, 07 Aug 2009 14:05:53 GMT</pubDate></item><item><title>Tuna Toksoz commented on Challenge: Find the bug fixes</title><description>Stephen,
  
I thought the same, the silent fail thing,it happened to me several times during dev, I had to catch the exception in the debugger to find the problem.
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment41</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment41</guid><pubDate>Fri, 07 Aug 2009 10:06:51 GMT</pubDate></item><item><title>Peter Morris commented on Challenge: Find the bug fixes</title><description>I think it is impossible to look at working code and guess what the error was in the old code that you have not seen.  There are millions of possibilities.
  
  
For example, I think the code was here...
  
  
You took out the NotImplementedException in CreateSessionFactory()
  
  
  
:-)
  
  
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment40</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment40</guid><pubDate>Fri, 07 Aug 2009 09:05:10 GMT</pubDate></item><item><title>Stephen commented on Challenge: Find the bug fixes</title><description>Meh, scratch that, aparently static init will def~ happen in context of the first request.. maybe related to static field init ordering?
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment39</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment39</guid><pubDate>Fri, 07 Aug 2009 09:04:58 GMT</pubDate></item><item><title>Stephen commented on Challenge: Find the bug fixes</title><description>The only thing I can think of is that perhaps the static init could silently fail, causing you to wonder why you don't have a session factory for subsequent requests.
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment38</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment38</guid><pubDate>Fri, 07 Aug 2009 09:01:16 GMT</pubDate></item><item><title>Tuna Toksoz commented on Challenge: Find the bug fixes</title><description>Application_Start is not viable as many instances of HttpApplication is created, the later ones will not benefit from this. Init may be used for that purpose, instead of Application_Start.
  
  
protected void Global() is not a ctor and this made confused :)
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment37</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment37</guid><pubDate>Fri, 07 Aug 2009 08:46:31 GMT</pubDate></item><item><title>Gareth commented on Challenge: Find the bug fixes</title><description>Do you need to set SessionFactory to null when the application ends to avoid memory leaks?
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment36</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment36</guid><pubDate>Fri, 07 Aug 2009 08:38:04 GMT</pubDate></item><item><title>Hendry Luk commented on Challenge: Find the bug fixes</title><description>&gt;I am not aware of the issue you brought up. 
  
  
Not sure if this is a problem in NH, but we had that problem in SharpArchitecture (or rather Fluent-NH) with IIS7 where NHibernate.Init() crashes when called in application_start.
  
[code.google.com/.../detail](http://code.google.com/p/sharp-architecture/issues/detail?id=72&amp;can=1&amp;q=application_start)  
  
So they changed it to singleton-method call in each Application_BeginRequest:
  
NHibernateInitializer.Instance().InitializeNHibernateOnce(
  
				() =&gt; NHibernateSession.Init(etc etc));
  
  
Anyway, maybe you changed it because you want it invoked only once... And we can't guarantee application_start to be called once in a lifeatime of an application, particularly in the case of application-pool recycling.
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment35</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment35</guid><pubDate>Fri, 07 Aug 2009 08:17:58 GMT</pubDate></item><item><title>Rafal commented on Challenge: Find the bug fixes</title><description>I think it's because there can be more than one Global instance.
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment34</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment34</guid><pubDate>Fri, 07 Aug 2009 07:57:09 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug fixes</title><description>Hendry,
  
You are correct about the change, but not about why I did it. I am not aware of the issue you brought up.
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment33</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment33</guid><pubDate>Fri, 07 Aug 2009 07:04:50 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug fixes</title><description>Mike,
  
You _really_ want to avoid putting the NH session in the ASP.Net session.
  
No, that is not it.
  
And sessions force serialization of requests anyway
  
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment32</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment32</guid><pubDate>Fri, 07 Aug 2009 07:03:19 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug fixes</title><description>Rafal &amp; Rob,
  
Yes, but can you explain why?
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment31</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment31</guid><pubDate>Fri, 07 Aug 2009 07:01:31 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug fixes</title><description>Stephen,
  
YES!
  
You got one of the problems, the event wiring _must_ happen in the ctor.
  
Application_Start, where I have seen a lot of people put them is going to cause problems when you have concurrent requests
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment30</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment30</guid><pubDate>Fri, 07 Aug 2009 07:00:51 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug fixes</title><description>Andy,
  
Very close, but you haven't explained why it will never get called or why it should be instance ctor
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment29</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment29</guid><pubDate>Fri, 07 Aug 2009 06:58:07 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Find the bug fixes</title><description>Frank,
  
No reason, it can be private as well.
</description><link>http://ayende.com/4103/challenge-find-the-bug-fixes#comment28</link><guid>http://ayende.com/4103/challenge-find-the-bug-fixes#comment28</guid><pubDate>Fri, 07 Aug 2009 06:56:07 GMT</pubDate></item></channel></rss>