This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 381 - Memory leak in asp.net with sessions enabled
: Memory leak in asp.net with sessions enabled
Status: NEW
Product: Class Libraries
Classification: Mono
Component: Sys.Web
: 2.10.x
: PC Linux
: --- normal
: ---
Assigned To: Marek Habersack
:
:
:
:
  Show dependency treegraph
 
Reported: 2011-08-24 11:52 EDT by Justen Hyde
Modified: 2012-10-02 06:38 EDT (History)
5 users (show)

See Also:
Tags:
Test Case URL:
External Submit: ---


Attachments
test case (72.29 KB, application/x-gzip)
2011-08-24 11:52 EDT, Justen Hyde
Details

Description Justen Hyde 2011-08-24 11:52:16 EDT
Created attachment 179 [details]
test case

A simple web application will consume ever increasing amounts of memory when
run with sessions enabled. This appears to be related to CacheItems being
created rapidly without being garbage collected. Behaviour seen with both boehm
and sgen collection.
See also http://go-mono.com/forums/#nabble-td3264509

Running on mono 2.10.2, observed with both mvc2 (test case attached) and mvc3.

To reproduce: Run the test case, point a couple of browser tabs at it and
monitor memory usage over time. This will take a while to become evident (since
CacheItems are small).

I suspect this is a cause of the mysterious problems that mono sites under high
load experience, referred to here
http://www.mono-project.com/Mod_mono#Under_high_load.2C_mono_process_consumes_a_lot_of_memory.2C_website_stops_responding
Comment 1 Jeffrey Stedfast 2011-08-24 12:30:29 EDT
Any chance you could test this on 2.10.4?
Comment 2 Justen Hyde 2011-08-25 16:37:42 EDT
I see exactly the same behaviour on 2.10.4
Comment 4 Jeffrey Stedfast 2011-09-29 12:24:44 EDT
Thanks Justin, looks like some of our devs are now able to reproduce. Hopefully
they can find & fix the issue :-)
Comment 6 Miguel de Icaza 2011-12-08 09:43:11 EST
Gonzalo, was this patch backported to 2-10?

This was on 2011-09-29/2011-09-30
Comment 7 Gonzalo Paniagua Javier 2011-12-08 16:27:31 EST
commit fc7ffed3acfa9f81943350c846cd393b472cfda0
Author: Gonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Date:   Fri Sep 30 01:20:29 2011 -0400

    Plug an unmanaged memory leak

        If Flush() was called with final_flush set to true, we were leaking the
        unmanaged memory in the output stream (if allocated).

        It was "only" an AS leak.

        Thanks to Kumpera for the help debugging this.
Comment 8 Gonzalo Paniagua Javier 2011-12-08 16:32:20 EST
...but that leak has nothing to do with sessions or caching
Comment 9 Dan Parnham 2012-01-20 07:56:41 EST
We're still seeing this issue with mono 2.10.8 unfortunately.

My test case uses the MVC3 and if I set:
<sessionState mode="Off" />
in the web.config it does not leak at all (running through XSP).

I discovered something new today when playing with the SessionState attribute,
since we may want to selectively enable/disable session state in our
application.

In my test case I set:
    <sessionState mode="InProc" cookieless="false" timeout="20" />
and then used:
    [SessionState(SessionStateBehavior.Disabled)]
in the controller.

This should have the same result as setting the session state mode to off in
the web.config, but only applied to specific controllers. However, I still saw
leaking of the same magnitude as before! 

Hopefully this information may be useful.
Comment 10 Dan Parnham 2012-01-20 08:36:31 EST
Update to my previous comment:

Having checked a few things I found that I could still write values into the
session in my controller, whereas it should be throwing an exception. It seems
that the controller SessionState is not being applied in mono (is this another
bug?).

The leak is still happening though and we have been working on the next version
of our application in the hope that this problem will be addressed before we
have to ship.
Comment 11 pgentoo 2012-10-02 02:51:26 EDT
Any status on this issue?  I also see significant leaks in my application,
requiring several restarts per day to keep things running smoothly.  :(
Comment 12 Dan Parnham 2012-10-02 06:38:34 EDT
We gave up hoping that this would be fixed and instead looked for an
alternative way of doing things. Since we had javascript heavy single-page
application it made sense to switch to a REST service based system running in a
console (mono + ubuntu).

We now use the awesome ServiceStack (http://www.servicestack.net/) running as a
daemon
(https://github.com/ServiceStack/ServiceStack/wiki/Run-ServiceStack-as-a-daemon-on-Linux).

I wrote a post about our problems and solutions at
http://blog.teadriven.me.uk/2012/03/time-for-rest.html

Note You need to log in before you can comment on or make changes to this bug.