我在托管服务上工作,该服务在Web角色的实例上部署了Windows Azure Cache。缓存在生产时启用,但在计算模拟器中我们禁用它,因为我们经常遇到缓存模拟器的减速和异常。特别是,在计算模拟器中,我们不在csdef
中加载缓存模块,并且在运行时我们通过创建DataCacheFactory
来检测是否启用了缓存,并捕获在角色中指示的角色时抛出的特定异常。在csdef
。
这在Windows Azure Caching 2.0之前正常工作 - 当我们升级到Windows Azure Caching 2.1(和Azure SDK 2.1)时,行为发生了变化:
DataCacheFactory
构造函数当我们尝试从DataCache
实例化DataCacheFactory
时,角色似乎挂起,3分钟后返回时出现以下异常(可以找到完整的文本{{3} }):
Microsoft.ApplicationServer.Caching.DataCacheException was unhandled by
user code
Message=ErrorCode<ERRCA0017>:SubStatus<ES0006>:There is a temporary failure.
Please retry later. (<snip>). Additional Information :
The client was trying to communicate with the server:
net.tcp://WebRole:24233.
InnerException: System.Net.Sockets.SocketException
Message=No such host is known
请注意,这不是以下SO问题的重复:
因为
答案 0 :(得分:1)
使用以下SO answer中描述的过程并在ILSpy的帮助下,我已经能够理解为什么会发生此异常:在Windows Azure Caching 2.1中,当找不到客户端配置中指定的角色时被认为是一个地址并继续执行,而在旧版本中,它会抛出一个异常(我知道缓存未被启用)。
相关的日志消息是:
WaWorkerHost.exe Information: 0 : INFORMATION:
<DistributedCache.CacheFactory.1> TryAutoDiscoverServersWithinDeployment
for Instance 'WebRole' failed to connect as RoleName type with exception
System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. --->
Microsoft.ApplicationServer.Caching.DataCacheException:
ErrorCode<UnspecifiedErrorCode>:SubStatus<ES0001>:The role WebService
was not found in the current deployment.
at Microsoft.ApplicationServer.Caching.AzureClientHelper.RoleUtility.
GetCacheRoleIPList(String roleName, String portIdentifier)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments,
Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,
Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters,
CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Microsoft.ApplicationServer.Caching.DataCacheFactory.
AutoDiscoverServersWithinDeployment()
at Microsoft.ApplicationServer.Caching.DataCacheFactory.
TryAutoDiscoverServersWithinDeployment()
Assuming it as EndPoint.
和
WaWorkerHost.exe Warning: 0 : WARNING: <DistributedCache.SocketClientChannel.1>
Request 1 to host net.tcp://webrolw:24233/ failed
Status=ChannelOpenFailed[System.Net.Sockets.SocketException (0x80004005):
No such host is known
要解决此问题,您可以:
DataCacheFactory
并查看Servers
属性中是否有任何项目的地址与缓存角色的名称相同 - 表示所指示的角色具有没有配置缓存; DataCacheFactory
的{{3}}属性中的重试次数(导致异常之前的3分钟延迟),如果抛出异常,则假设缓存不可用。