C# 从控制器调用异步/等待时Windows Azure引发死锁错误
异步模块或处理程序在异步 行动仍在进行中 我只在Azure中遇到此错误。我在事件日志中看到以下错误:C# 从控制器调用异步/等待时Windows Azure引发死锁错误,c#,asynchronous,task,async-await,C#,Asynchronous,Task,Async Await,异步模块或处理程序在异步 行动仍在进行中 我只在Azure中遇到此错误。我在事件日志中看到以下错误: <Event> <System> <Provider Name="ASP.NET 4.0.30319.0" /> <EventID>1309</EventID> <Level>2</Level> <Task>0</Task>
<Event>
<System>
<Provider Name="ASP.NET 4.0.30319.0" />
<EventID>1309</EventID>
<Level>2</Level>
<Task>0</Task>
<Keywords>Keywords</Keywords>
<TimeCreated SystemTime="4:13:44 PM" />
<EventRecordID>138984609</EventRecordID>
<Channel>Application</Channel>
<Computer>***********</Computer>
<Security />
</System>
<EventData>
<Data>3005</Data>
<Data>An unhandled exception has occurred.</Data>
<Data>12/15/2013 4:13:44 PM</Data>
<Data>12/15/2013 4:13:44 PM</Data>
<Data>*****************</Data>
<Data>134</Data>
<Data>9</Data>
<Data>0</Data>
<Data>/LM/W3SVC/2007260606/ROOT-25-**************</Data>
<Data>Full</Data>
<Data>/</Data>
<Data>C:\DWASFiles\Sites\*******\VirtualDirectory0\site\wwwroot\</Data>
<Data>RD00155D44211F</Data>
<Data />
<Data>1788</Data>
<Data>w3wp.exe</Data>
<Data>IIS APPPOOL\********</Data>
<Data>InvalidOperationException</Data>
<Data>An asynchronous module or handler completed while an asynchronous operation was still pending.</Data>
<Data>https://*********.azurewebsites.net:443/auth/login</Data>
<Data>/auth/login</Data>
<Data>********</Data>
<Data />
<Data>False</Data>
<Data />
<Data>IIS APPPOOL\******</Data>
<Data>52</Data>
<Data>IIS APPPOOL\*******</Data>
<Data>False</Data>
<Data />
</EventData>
</Event>
1309
2.
0
关键词
138984609
应用
***********
3005
发生了未处理的异常。
2013年12月15日下午4:13:44
2013年12月15日下午4:13:44
*****************
134
9
0
/LM/W3SVC/2007260606/ROOT-25-**************
满满的
/
C:\DWASFiles\Sites\******\VirtualDirectory0\site\wwwroot\
RD00155D44211F
1788
w3wp.exe
IIS应用程序池\********
无效操作例外
异步模块或处理程序在异步操作仍挂起时完成。
https://*********.azurewebsites.net:443/auth/login
/身份验证/登录
********
假的
IIS应用程序池\******
52
IIS应用程序池\*******
假的
现在我认为这是由调用一些异步代码引起的:
public async Task<ActionResult> Login()
{
if (Request.HttpMethod == "POST")
{
var userInputName = await session.Get<string>("UserInputName");
var userCode = Request[userInputName];
var getAuthCtxRsp = await someService.GetAuthenticationContext(new UserCodeGetAuthenticationContextRequest
{
SessionKey = await sessionResolver.GetSessionKey(),
UserCode = userCode
});
// Some stuff removed here...
if (getAuthCtxRsp.ChallengeRequired)
{
await session.Put("Challenge", getAuthCtxRsp.Challenge, TimeSpan.FromMinutes(20));
await session.Put("NextPage", "/auth/password", TimeSpan.FromMinutes(20));
return new RedirectResult("/auth/challenge/");
}
return new RedirectResult("/auth/password");
}
// More stuff happens here....
await session.Put("UserInputName", model.UserInputName, TimeSpan.FromMinutes(20));
return View(model);
}
公共异步任务登录()
{
if(Request.HttpMethod==“POST”)
{
var userInputName=await session.Get(“userInputName”);
var userCode=Request[userInputName];
var getAuthCtxRsp=等待someService.GetAuthenticationContext(新用户代码getAuthenticationContextRequest
{
SessionKey=等待sessionResolver.GetSessionKey(),
UserCode=UserCode
});
//这里有些东西被移走了。。。
if(需要getAuthCtxRsp.Challenger)
{
等待session.Put(“Challenge”,getAuthCtxRsp.Challenge,TimeSpan.FromMinutes(20));
等待session.Put(“NextPage”,“auth/password”,TimeSpan.FromMinutes(20));
返回新的重定向结果(“/auth/challenge/”;
}
返回新的重定向结果(“/auth/password”);
}
//这里发生了更多的事情。。。。
wait session.Put(“UserInputName”,model.UserInputName,TimeSpan.frommins(20));
返回视图(模型);
}
它似乎位于发生错误的if(Request.HttpMethod==“POST”)
中
这仅在部署到Azure时发生。我认为这是因为它需要更长的时间才能到达会话服务,而不是在我的本地机器上(但我不确定)
我还向global.asax添加了一个全局错误处理程序,但没有看到任何日志记录(但我不确定这是否是因为日志记录服务还使用异步方法发送日志记录语句)
想法?看起来您有许多
async
方法没有遵循,所以我假设这些方法是您自己编写的。此错误最可能的原因是方法的包装,可能在async
方法中