当在模拟器中本地运行时,Web Worker 工作正常。但是,每当我更新在 Azure VM 上运行的 Web Worker 时,我都会在事件查看器中收到以下异常,并且该角色不会启动:
Application: WaWorkerHost.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AggregateException
Stack: at System.Threading.Tasks.Task.Wait(Int32, System.Threading.CancellationToken) at System.Threading.Tasks.Task.Wait()
at Foo.PushProcess.WorkerRole.Run()
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.StartRoleInternal() at Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.b__2() at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()Inner Exception: A task was canceled.
Faulting application name: WaWorkerHost.exe, version: 2.6.1198.712, time stamp: 0x54eba731
Faulting module name: KERNELBASE.dll, version: 6.3.9600.17415, time stamp: 0x54505737
Exception code: 0xe0434352
Fault offset: 0x0000000000008b9c
Faulting process id: 0xfb8
Faulting application start time: 0x01d11e3128981a5d
Faulting application path: E:\base\x64\WaWorkerHost.exe
Faulting module path: D:\Windows\system32\KERNELBASE.dll
Report Id: 30631c5c-8a25-11e5-80c6-000d3a22f3ec
Faulting package full name:
Faulting package-relative application ID:
Session "MA_ETWSESSION_WAD_415df88f8a0447178dbd4c18f1349f0e_Foo.PushProcess_Foo.PushProcess_IN_0" failed to start with the following error: 0xC0000035
这是相关代码:
public override void Run()
{
Trace.TraceInformation("Foo.PushProcess is running");
try
{
RunAsync(_cancellationTokenSource.Token).Wait(); // This is where the exceptions point to
}
catch (Exception ex)
{
Trace.TraceError("[WORKER] Run error: " + ex);
}
finally
{
_runCompleteEvent.Set();
}
}
public override bool OnStart()
{
// Set the maximum number of concurrent connections
ServicePointManager.DefaultConnectionLimit = 12;
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
bool result = base.OnStart();
_storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
var queueClient = _storageAccount.CreateCloudQueueClient();
_pushQueue = queueClient.GetQueueReference("pushes");
_pushQueue.CreateIfNotExists();
CreatePushBroker();
Trace.TraceInformation("Foo.PushProcess has been started");
return result;
}
private async Task RunAsync(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
Trace.TraceInformation("Working");
CloudQueueMessage message = null;
try
{
message = _pushQueue.GetMessage();
if (message != null)
{
ProcessItem(message);
}
}
catch (Exception ex)
{
if (message != null && message.DequeueCount > 5)
_pushQueue.DeleteMessage(message);
Trace.TraceError("[WORKER] Retrieval Failure: " + ex);
}
await Task.Delay(1000, cancellationToken);
}
}
请注意,一些代码已被省略,但是这些代码都是在初始化后运行的,理论上此异常不会到达。
我完全不知道是什么导致了这个问题。任何帮助将不胜感激 - 即使只是为了帮助我获得有用的异常(exception)。
更新
我现在已经将我的代码减少到下面 - 它就像网络 worker 一样简单 - 并且我仍然遇到异常。我认为要么是旧的工作线程被缓存,要么是部署过程中存在问题。
public override void Run()
{
Trace.TraceInformation("Foo.PushProcess is running");
try
{
RunAsync(_cancellationTokenSource.Token).Wait(); // This is where the exceptions point to
}
catch (Exception ex)
{
Trace.TraceError("[WORKER] Run error: " + ex);
}
finally
{
_runCompleteEvent.Set();
}
}
public override bool OnStart()
{
// Set the maximum number of concurrent connections
ServicePointManager.DefaultConnectionLimit = 12;
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
bool result = base.OnStart();
return result;
}
private async Task RunAsync(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
Trace.TraceInformation("Working");
// code removed for testing - no work is being done.
await Task.Delay(1000, cancellationToken);
}
}
最佳答案
我尝试了一下,但没能在我这边重现。我有来自 MSDN Azure 镜像的 VS 2015 Enterprise (14.0.23107.0 D14REL),我使用 .Net Fx 版本 4.6 部署运行。我安装了 Azure 工具和 SDK 2.8。我使用 .NET Fx 4.5.2 创建了一个新的 Azure 云服务,并添加了一个辅助角色。
我刚刚运行了您的一些稀疏代码模板,如下所示:
public class WorkerRole : RoleEntryPoint
{
private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
private readonly ManualResetEvent runCompleteEvent = new ManualResetEvent(false);
private CloudQueue _pushQueue;
private CloudStorageAccount _storageAccount;
public override void Run()
{
Trace.TraceInformation("WorkerRole1 is running");
try
{
this.RunAsync(this.cancellationTokenSource.Token).Wait();
}
catch (Exception ex)
{
Trace.TraceError("[WORKER] Run error: " + ex);
}
finally
{
this.runCompleteEvent.Set();
}
}
public override bool OnStart()
{
// Set the maximum number of concurrent connections
ServicePointManager.DefaultConnectionLimit = 12;
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
bool result = base.OnStart();
_storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
var queueClient = _storageAccount.CreateCloudQueueClient();
_pushQueue = queueClient.GetQueueReference("pushes");
_pushQueue.CreateIfNotExists();
CreatePushBroker();
Trace.TraceInformation("Foo.PushProcess has been started");
return result;
}
private void CreatePushBroker()
{
return;
}
public override void OnStop()
{
Trace.TraceInformation("WorkerRole1 is stopping");
this.cancellationTokenSource.Cancel();
this.runCompleteEvent.WaitOne();
base.OnStop();
Trace.TraceInformation("WorkerRole1 has stopped");
}
private async Task RunAsync(CancellationToken cancellationToken)
{
// TODO: Replace the following with your own logic.
while (!cancellationToken.IsCancellationRequested)
{
Trace.TraceInformation("Working");
CloudQueueMessage message = null;
try
{
message = _pushQueue.GetMessage();
if (message != null)
{
ProcessItem(message);
}
}
catch (Exception ex)
{
if (message != null && message.DequeueCount > 5)
_pushQueue.DeleteMessage(message);
Trace.TraceError("[WORKER] Retrieval Failure: " + ex);
}
await Task.Delay(1000, cancellationToken);
}
}
private void ProcessItem(CloudQueueMessage message)
{
return;
}
}
}
它在本地模拟器中运行没有问题,我继续将其部署到美国西部,并在小型实例虚拟机上启用了 IntelliTrace,但遇到了部署问题。它在 WA-GUEST-OS-4.26_201511-0 guest 工作角色镜像上运行,我能够通过 RDP 连接到计算机,并且没有看到与代码或计算机相关的任何问题。您是否有任何其他二进制文件可能未包含在包中,或者可能存在一些未正确定义的依赖项,或者存储帐户命名问题?
这是我的部署日志。正如您所看到的,大约花了 7 分钟,因为我只是为了好玩而从美国东部提取存储:
1:11:25 AM - 警告:存在软件包验证警告。 1:11:26 AM - 检查远程桌面证书... 1:11:26 AM - 上传证书... 1:11:42 AM - 应用诊断扩展。 上午 1:12:24 - 准备部署 AzureCloudService1 - 2015 年 11 月 24 日上午 1:11:19,订阅 ID 为“9a4715f5-acb8-4a18-8259-1c28b92XXXXX”,使用服务管理 URL“https://management.core.windows.net/” '... 1:12:24 AM - 正在连接... 1:12:24 AM - 正在验证存储帐户“ericgoleastus”... 1:12:24 AM - 上传包... 1:12:28 AM - 创建... 凌晨 1:13:15 - 创建的部署 ID:c5f26568707b46a3bd42466dd0bf7509。 1:13:15 AM - 角色 WorkerRole1 的实例 0 正在创建虚拟机 凌晨 1:13:15 - 开始... 1:13:32 AM - 正在初始化... 1:14:36 AM - 角色 WorkerRole1 的实例 0 正在启动虚拟机 1:16:11 AM - 角色 WorkerRole1 的实例 0 处于未知状态 1:16:43 AM - 角色 WorkerRole1 的实例 0 正忙 详细信息:正在启动角色...系统正在初始化。 [2015-11-24T01:16:08Z] 1:19:50 AM - 角色 WorkerRole1 的实例 0 已准备就绪 1:19:50 AM - 创建的 Web 应用程序 URL:http://quequetest.cloudapp.net/ 凌晨 1:19:50 - 完成。
请告诉我们您是否可以在启用 IntelliTrace 的情况下获得更多详细信息。
问候, 埃里克
关于c# - 无法启动 Azure 辅助角色,异常代码 0xe0434352 和 0xC0000035,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33698286/