0

我在一个托管服务上工作,该服务在 Web 角色的实例上部署了 Windows Azure 缓存。缓存在生产中启用,但在计算模拟器中我们禁用它,因为我们经常遇到缓存模拟器的减速和异常。特别是,在计算仿真器中,我们csdef不会DataCacheFactorycsdef.

这在 Windows Azure Caching 2.0 之前一直有效——当我们升级到 Windows Azure Caching 2.1(和 Azure SDK 2.1)时,行为发生了变化:

  • 我们在构造函数上没有例外DataCacheFactory
  • 当我们尝试DataCache从角色实例化时,DataCacheFactory该角色似乎挂起,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 问题的重复:

自从

  • 我确定我使用的是 Azure SDK 2.1(我已检查调试库版本是否正确);
  • 只有当我故意禁用缓存角色时才会出现我的问题。
4

1 回答 1

1

使用以下SO 答案中描述的过程并在 ILSpy 的帮助下,我已经能够理解为什么会发生此异常:在 Windows Azure 缓存 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属性中是否有地址与缓存角色名称相同的项目——表明指定角色没有配置缓存;
  • 在托管服务的调试配置中,降低CacheReadyRetryPolicy属性中的重试次数DataCacheFactory (这导致异常发生前的 3 分钟延迟),如果抛出异常,则假定缓存不可用。
于 2013-10-07T17:50:57.767 回答