1

I have migrated my project from MSSQL to MySQL and one of the feature I have to implement is a possibility to store sessions on db side, hence custom session store provider has to be configured. I used MySQL connector for visual studio to properly setup session provider. Here is a snippet from my web.config:

<connectionStrings>
<remove name="LocalMySqlServer" />
<add name="LocalMySqlServer" connectionString="server=<SERVER>;user=<USER>;pwd=<PASSWORD>;port=<PORT>;database=<DBNAME>;AutoEnlist=false;" providerName="MySql.Data.MySqlClient" />
</connectionStrings>

 <system.web>
 <sessionState mode="Custom" cookieless="false" timeout="20" allowCustomSqlDatabase="true"  regenerateExpiredSessionId="true" customProvider="MySqlSessionStateProvider">
  <providers>
    <clear/>
    <add name="MySqlSessionStateProvider" type="MySql.Web.SessionState.MySqlSessionStateStore, MySql.Web, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="/" description="My Local Session State" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="True" autogenerateschema="True" enableExpireCallback="False" />
  </providers>
</sessionState>
...
</system.web>

Once I run my application db schema was modified and all required tables were created:

enter image description here

Furthermore, I detected that during execution session table is filling by session info so I it is a good signal that connection works and MySQL custom provider is doing what is supposed to do.

enter image description here

Unfortunately, after some time my application fails due to System.OutOfMemoryException. The stack trace looks like:

enter image description here

My assumption is that there is some problem with session items deserialization. I have a few classes which are stored in a session and all of them are marked by appropriate [Serializable] attribute. Other items has primitive types (bool, int..) So, my question is what else could cause this issue? The problem is that I even can't detect exact place from where this issue is firing. Any suggestion are appreciated.

mbigun
  • 1,304
  • 4
  • 19
  • 46
  • Such problems are hard to debug without having access to code. With sql server exactly the same code worked fine? What are the classes you store in your session? Do you see sessions are growing in size over time in your database? – Evk Apr 04 '16 at 20:23
  • Your problem is that, likely due to some bug in the code somewhere, you are storing more and more items in your `SessionStateItemsCollection`, until eventually it becomes impossible to allocate a large enough contiguous memory buffer for the underlying array needed to hold all the items, and you get this exception. For array size limits, see http://stackoverflow.com/questions/5367320 or http://stackoverflow.com/questions/23206496 or maybe https://blogs.msdn.microsoft.com/ericlippert/2009/06/08/out-of-memory-does-not-refer-to-physical-memory/. – dbc Apr 04 '16 at 23:55
  • Can you directly query your MySQL database to see how large your session stores have become, and what is taking all the space? – dbc Apr 04 '16 at 23:56

1 Answers1

0

Can you please recheck that all items inside your classes are public [ private members would not be taken care of during serialization].