I finally managed to reproduce the problem and it turned out that I
was returning a non-evaluated query from my service.
The problem was reproduced by making two or more simultaneous requests
and it resulted in really weird problems where the session got shared
between threads and other concurrency problems.
That enumerable was then traversed in the view generating queries in a
loop. My session was already disposed but got picked up again when
evaluating the query.
First I solved the problem by disposing my session in
Application_EndRequest, since that is run after the views are
rendered. but that didn't seem right so then I find the service method
returning the unevaluated enumerable, and did a ToList() on it and now
I can once again dispose my connection in the OnActionExecuted method
in my parent controller.
The code in my session is was not the problem (as it is basically very
similar to the Session class in the NoRM Tests), but I think it would
be good for people doing the same "parent controller" thingy :) that
I've done to recognize this problem. Here's an example:
All my controllers are extending ArrivalguidesController
[Localization]
[HandleError]
public class ArrivalguidesController : Controller
{
protected readonly MongoSession _session;
protected DestinationMenu MainMenu;
public ArrivalguidesController(MongoSession session)
{
//the session class is instantiated using StructureMap
_session = session;
}
protected override void OnActionExecuted(ActionExecutedContext
filterContext)
{
if (ViewData.Model is MasterViewModel)
{
var cachedMainMenu = HttpRuntime.Cache.Get("MainMenu") as
DestinationMenu;
if(cachedMainMenu == null)
{
cachedMainMenu =
_session.All<DestinationMenu>().FirstOrDefault();
HttpRuntime.Cache["MainMenu"] = cachedMainMenu;
}
((MasterViewModel)ViewData.Model).MainMenu = MainMenu =
cachedMainMenu;
if(string.IsNullOrEmpty(((MasterViewModel)ViewData.Model).Language))
((MasterViewModel)ViewData.Model).Language =
CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
}
//disposing in the session
//Make sure not to have any unevaluated linq-expressions that would
be evaluated in the views or you'll be in trouble
_session.Dispose();
base.OnActionExecuted(filterContext);
}
}
So I hope this will help someone in a similar situation.
On Jun 10, 1:07 pm, Andrew Theken <
athe...@gmail.com> wrote:
> Out of Memory exceptions can happen for all sorts of reasons, not always
> because the process is "Out of Memory" - fragmentation is one cause for
> these types of issues, but Karl has worked quite a bit on the driver to help
> avoid this..
>
> Without seeing some code, I am not sure I can be very helpful. can you post
> the "MongoSession" code you're working from? Are you disposing each "Mongo"
> object that you create?
>
> //Andrew Theken
>
> On Thu, Jun 10, 2010 at 4:14 AM, Anders Fredriksson <
>
>
>
>
anders.fredriks...@visit.com> wrote:
> > Hi,
>
> > I've implemented a new site in
asp.net MVC2 using mongodb as the only
> > backend database and I'm having big issues with what I think is the
> > conneciton pool.
>
> > Right now the site is up athttp://beta.arrivalguides.comand it has
> >
norm-mongodb...@googlegroups.com<norm-mongodb%2Bunsubscribe@google
groups.com>
> > .