Alachisoft / NCache

NCache: Highly Scalable Distributed Cache for .NET
http://www.alachisoft.com
Apache License 2.0
647 stars 123 forks source link

Unable to cast object of type 'System.Int32' to type 'System.Collections.ArrayList'." #30

Open felixmondelo opened 5 years ago

felixmondelo commented 5 years ago

Hi,

We have a replicated cache with 2 nodes, from time to time, we received this error and we aren't able to resolve: "Unable to cast object of type 'System.Int32' to type 'System.Collections.ArrayList'."

The stacktrace:

at Alachisoft.NCache.Web.Command.CommandResponse.ParseResponse()
at Alachisoft.NCache.Web.Caching.RemoteCache.Add(String key, Object value, CacheDependency dependency, CacheSyncDependency syncDependency, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, Int16 removeCallback, Int16 updateCallback, Int16 dsItemAddedCallback, Boolean isResyncExpiredItems, String group, String subGroup, Hashtable queryInfo, BitSet flagMap, String providerName, String resyncProviderName, EventDataFilter updateCallbackFilter, EventDataFilter removeCallabackFilter, Int64 size, String clientId)
   at Alachisoft.NCache.Web.Caching.Cache.AddOperation(String key, Object value, CacheDependency dependency, CacheSyncDependency syncDependency, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, DSWriteOption dsWriteOption, CacheItemRemovedCallback onRemoveCallback, CacheItemUpdatedCallback onUpdateCallback, DataSourceItemsAddedCallback onDataSourceItemAdded, Boolean isResyncExpiredItems, String group, String subGroup, Tag[] tags, String providerName, String resyncProviderName, NamedTagsDictionary namedTags, CacheDataNotificationCallback cacheItemUdpatedCallback, CacheDataNotificationCallback cacheItemRemovedCallaback, EventDataFilter itemUpdateDataFilter, EventDataFilter itemRemovedDataFilter, Int64& size, Boolean allowQueryTags, String clientId, Int16 updateCallbackID, Int16 removeCallbackID, Int16 dsItemAddedCallbackID)
   at Alachisoft.NCache.Web.Caching.Cache.Add(String key, CacheItem item, DSWriteOption dsWriteOption, DataSourceItemsAddedCallback onDataSourceItemAdded)
   at Alachisoft.NCache.Web.Caching.Cache.Add(String key, CacheItem item)

In the log files we see:

...received response for request 118849, sender=:7800, val=System.Byte[] ...received response for request 118849, sender=:7800, val=Alachisoft.NCache.Common.DataStructures.Clustered.ClusteredArrayList

How can we resolve this problem?

Ollie-NCache commented 5 years ago

Hi Felix,

To get to the root of the issue, I will need a couple of pieces of information from you:

1) What version of NCache are you using? 2) Is the NCache installation Enterprise or Open Source? 3) Exact steps to reproduce the problem. A working sample from your end will be great.

This will go through a review and find out what happened.

felixmondelo commented 5 years ago

Hi Ollie,

  1. Version 4.9.0
  2. Open source
  3. We don't know :-(, is only after some restarts.

Regards.

Ollie-NCache commented 5 years ago

Hi Felix,

If you can attach the client log and the log files from both servers for the times when this error occurred, we'll take a look at them and see if we can reproduce the problem. The client log can be retrieved from %NCHOME%\NCache\log-files\ClientLogs on the client machine and the server logs can be found at %NCHOME%\NCache\log-files on each server node against the name of the cache. Note that %NCHOME% is the installation directory e.g. C:\Program Files.

felixmondelo commented 5 years ago

NCache.log

Brad-NCache commented 5 years ago

Hi Felix,

I will look into the matter. In the mean time, can you update me with the following information:

  1. A snippet of your code where you are using NCache. I would need the exact NCache function calls and the parameters and values thereof where this scenario is observed. These include information on whether its a Get, Add, Insert, Remove call, expirations if set and what kind (absolute or sliding expirations), what type and value of objects are being inserted etc.

  2. Please provide the client logs as well where this scenario is being seen.

I would need this in order to be able to reproduce the problem.

felixmondelo commented 5 years ago

Hi,

  1. Always are Get and Add operations, but the error seems that is on Add operations. The code is:
 // Initialize an instance of the cache to begin performing operations:
            _cache = Alachisoft.NCache.Web.Caching.NCache.InitializeCache(cache);

            string queryText = String.Format("SELECT SettingValue FROM dbo.AppSettings WHERE SettingKey = '{0}'", settingKey);

            // Let's create SQL depdenency
            CacheDependency sqlServerDependency = new SqlCacheDependency(SettingsConnectionString, queryText);
            CacheItem cacheItem = new CacheItem(settingValue);
            cacheItem.Dependency = sqlServerDependency;

            string cacheKey = GenerateCacheKey(settingKey);
            _cache.Add(cacheKey, cacheItem);
  1. I attach the client logs. ClientLogs..txt
felixmondelo commented 5 years ago

Hi, any ideas?

We have identified how to solve the problem when it happens, but we don't know why it happens from time to time.

When we see this entry in the log:

Alachisoft.NCache.CacheHost.exe settingsCache 134 INFO GroupRequest.doExecute() received all responses: [GroupRequest: req_id=816269 members: 172.17.12.179:7800 172.17.12.177:7800 172.17.12.183:7800 172.17.12.184:7800 172.17.12.185:7800 172.17.12.178:7800 responses: System.Byte[] Alachisoft.NCache.Common.DataStructures.Clustered.ClusteredArrayList Alachisoft.NCache.Common.DataStructures.Clustered.ClusteredArrayList Alachisoft.NCache.Common.DataStructures.Clustered.ClusteredArrayList Alachisoft.NCache.Common.DataStructures.Clustered.ClusteredArrayList Alachisoft.NCache.Common.DataStructures.Clustered.ClusteredArrayList request_msg: Alachisoft.NCache.Cluster.Message rsp_mode: 2 done: False timeout: 60000 expected_mbrs: 0 ]

We know that we have to restart the cache from that node (the node that sends Byte[] instead of ClusteredArrayList) and the NCache began to work as usual.

The error is only for add new values on the cache, if a value is in the cache, we can get it without errors.

Thanks

felixmondelo commented 5 years ago

Please, I need a solution urgently... I don't know why from time to time, one of the servers sends Byte[] instead of ClusteredArrayList and why this makes the Add items to the cache, doesn't works.

Please any kind of fix?

Brad-NCache commented 5 years ago

Hi Felix,

I have tried to reproduce the scenario you are facing and have also consulted Engineering regarding it but have not been successful so as to come to the root cause of this. This is most probably a network-related issue.

If its possible, we can have a session wherein you can show your environment and produce the behavior so we can analyse it. Please contact support@alachisoft.com and give your contact information so we can set this up.