I have a problem where occasionally we are getting errors on our webservice. It’s adding a duplicate key to the dictionary in a function that gets the userid from the database in a homegrown digest authentication scheme. The function is real simple and the keys are hardcoded that get added and the new occurs on the dictionary immediately preceding. So really the only way this could happen is if multiple threads were running the function at once. It is a static function so I’m sure that’s what is happening. The stacktrace looks something like this.
system.collections.hashtable.insert(Object key, Object nValue, Boolean add)
system.collections.specialized.NameobjectCollectionbase.baseAdd(String name, object value)
SecMan.Getuser(String Username)
Sec.AuthenticationModule.OnAuthenticateRequest(Object source,EventArgs eventArgs)
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
It’s just happening on one server, everyone else is fine.
I’m a winforms guy and don’t know much about iis. Is the code in my SecMan.DLL getting executed asynchronously as I suspect? Does it always? If so it would seem like there would be problems more often at other sites. I’d like to nail down a definite cause before I roll out some kind of fix as it’s a big hassle.
Thanks,
Yes, web apps (including web services) are asynchronous. If SecMan is a singleton, and you’re sharing it across multiple web requests, you need to make it thread safe.