[Mono-dev] Bug in System.Web.Caching.Get() / Timer.Change() ?

jriepshoff at ujam.com jriepshoff at ujam.com
Thu Dec 9 03:30:45 EST 2010


Sorry Michal,

i made a mistake. we DISABLED it to make it work.
Since the code in System.Web.Cache looks as follows:

public object Get(string key)

{

Dictionary<string, CacheItem> V_0 = this.cache;

Monitor.Enter(V_0);

try

{

}

finally

{

Monitor.Exit(V_0);

}

if (!this.cache.TryGetValue(key, &CacheItem V_1))

{

object V_2 = null;

}

else

{

if (V_1.Dependency)

{

if (V_1.Dependency.HasChanged)

{

this.Remove(V_1.Key, 4, 0);

V_2 = null;

}

else

{

if (V_1.SlidingExpiration != Cache.NoSlidingExpiration)

{

V_1.AbsoluteExpiration = DateTime.get_Now() + V_1.SlidingExpiration;

V_1.Timer.Change((long)&V_1.SlidingExpiration.get_TotalMilliseconds(), (long)-1);

}

else

{

if (DateTime.get_Now() >= V_1.AbsoluteExpiration)

{

this.Remove(key, 2, 0);

V_2 = null;

}

else

{

V_2 = V_1.Value;

}

}

}

}

}

return V_2;

}


So, you have to take a look at System.Web.Cache.Insert()
Insert the items with AbsoluteExpiration + ((SlidingExpiration = TimeSpan.Zero (TimeSpanZero == Cache.NoSlidingExpiration))
Of course if you do this, you have to take care of the AsoluteExpiration DateTime to be so much in the future that it doesn't break the user's session and - not less important - to remove the item from the cache again when the user left and you've chosen a very long expiration time.


I do it as follows:
HttpRuntime.Cache.Insert(client.Id, client, null,  DateTime.Now.AddDays(1), TimeSpan.Zero, CacheItemPriority.NotRemovable, new CacheItemRemovedCallback(this.RemovedCallback));


And on ClientAppLeave i remove the cache item again.

Not the cleanest solution but better than the mono bug - which only happens when many users are connected for a short time and reconnect again and again (Stress Test in my case).
Under which circumstances does this bug occur in your app?




Best
Jan




On Dec 8, 2010, at 9:09 PM, <michal.x.malek at us.hsbc.com<mailto:michal.x.malek at us.hsbc.com>> wrote:

Hi J,

Could you confirm if enabling sliding expiration is still working for you
(preventing System.ArgumentException: Key 'System.Threading.Timer' already
exists in list issue).
I will be glad if you let me know, as we are planning to enable this in our
production environment today.

I appreciate any kind of feedback.

Best Regards,
--
Michal X Malek
HSBC Securities / Barracuda IT
Senior Development Specialist
michal.x.malek at us.hsbc.com<mailto:michal.x.malek at us.hsbc.com>



 From:       Michal X Malek/HBUS/HSBC

 To:         "jriepshoff at ujam.com" <jriepshoff at ujam.com>

 Date:       12/06/2010 09:21 AM

 Subject:    Re: [Mono-dev] Bug in System.Web.Caching.Get() / Timer.Change() ?





Hi,

Thanks for the response, we will test it.

Best Regards,
--
Michal X Malek
HSBC Securities / Barracuda IT
Senior Development Specialist
michal.x.malek at us.hsbc.com




 From:       "jriepshoff at ujam.com" <jriepshoff at ujam.com>

 To:         Michal X Malek/HBUS/HSBC at HSBC02

 Date:       12/05/2010 06:16 AM

 Subject:    Re: [Mono-dev] Bug in System.Web.Caching.Get() / Timer.Change() ?






I just enabled sliding expiration. That prevents the error - but costs
security, which is not an issue in my case.









On Dec 3, 2010, at 8:27 PM, michalm82 wrote:


I'm experiencing same issue, I'm on mono 2.6.7. Does migration to 2.8.1
helps
?
--
View this message in context:
http://mono.1490590.n4.nabble.com/Bug-in-System-Web-Caching-Get-Timer-Change-tp3053688p3071629.html

Sent from the Mono - Dev mailing list archive at Nabble.com.
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

------------------------
******************************************************************
This message originated from the Internet.  Its originator may or
may not be who they claim to be and the information contained in
the message and any attachments may or may not be accurate.
******************************************************************




-----------------------------------------
******************************************************************
This E-mail is confidential. It may also be legally privileged. If
you are not the addressee you may not copy, forward, disclose or
use any part of it. If you have received this message in error,
please delete it and all copies from your system and notify the
sender immediately by return E-mail.

Internet communications cannot be guaranteed to be timely, secure,
error or virus-free. The sender does not accept liability for any
errors or omissions.
******************************************************************
SAVE PAPER - THINK BEFORE YOU PRINT!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20101209/a712f483/attachment-0001.html 


More information about the Mono-devel-list mailing list