Description
Hi Team,
We are one of the heavy users of this framework for our retail application .
We see this below issue intermittently 3 or 4 times a month which blocks the users from checking out . The only way to fix it is restarting the app pool. Until the app pool is restarted out checkout screen breaks
Analysis :
To replicate the issue in lower environment we started hitting the service from our app while the app is getting recycled or redeployed. (in sandbox)
The HTTPUtility is the entry point class for any API calls that goes to Authorize and it has this Static Properties which invokes the AuthorizeNet.Envvironment.getBooleanProperty()
The issue seems to be coming from this class AuthorizeNet. Environment.GetProperty() (https://github.com/AuthorizeNet/sdk-dotnet/blob/master/Authorize.NET/Environment.cs)
When the app is getting recycled or deployed , the ConfigurationManager.AppSettings native object is in the process of getting populated with appsettings propery from Web.config file ,
Since it is a NameValue collection , (which is not ThreadSafe )if any other process tried to read the ConfigurationManager.AppSettings.AllKeys , the below exception is thrown .
And the Problem with Static attributes is that if gets corrupted due to an error , the only way to fix that is by getting app pool restarted
Proposed Fix:
Please let us know if there is a way to get around this issue . If not this is what we tried and it seems if you make this change in the Environment.cs File it might work
We tested by bombarding requests the below snippet of code when the app is getting recycled , an error gets thrown when the “ConfigurationManager.AppSettings.AllKeys” gets invoked.
Microsoft documentation says it’s a NamedValue collection by design (which is not thread safe). Hence when other process is trying to access it when it is written it throws an error
We tried this snippet and bombarded with similar load and it seems to do the trick as it doesn’t access AllKeys variable and right after we added the snippet that is similar to Environment.CS file and it fails
Conclusion :
Changing the way ConfigurationManager.AppSettings is read might fix the issue (By not accessing AllKeys)
Or Please let us know if there is a different way to handle this issue