You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Mediator.Net with Autofac in an ASP.NET WebApi2 project. I've found out the IRequestHandler is not working properly when it's an async method with awaits.
I was able to reproduce the issue on a blank new WebApi project with the following code:
publicclassDefaultController:ApiController{privatereadonlyIMediatorm;publicDefaultController(IMediatorm)=>this.m =m;[Route("ping"),HttpGet]publicasyncTask<IHttpActionResult>Ping()=> Ok(await m.RequestAsync<Ping,Pong>(new Ping()));[Route("hang"),HttpGet]publicasyncTask<IHttpActionResult>Ping2()=> Ok(await m.RequestAsync<Ping2,Pong2>(new Ping2()));}publicclassPing:IRequest{}publicclassPing2:IRequest{}publicclassPong:IResponse{}publicclassPong2:IResponse{}publicclassWorkingHandler:IRequestHandler<Ping,Pong>{publicTask<Pong>Handle(ReceiveContext<Ping>context){return Task.FromResult(new Pong());}}publicclassBrokenHandler:IRequestHandler<Ping2,Pong2>{publicasyncTask<Pong2>Handle(ReceiveContext<Ping2>context){await Task.Yield();// Or whatever awaitablereturnnew Pong2();// Never reached}}
I'm using Mediator.Net with Autofac in an ASP.NET WebApi2 project. I've found out the IRequestHandler is not working properly when it's an async method with awaits.
I was able to reproduce the issue on a blank new WebApi project with the following code:
The Configuration is as folllows:
The
/ping
endpoint works as expected. The/hang
endpoint never terminates.I was not able to reproduce the issue in unit tests. It only happens in ASP.NET.
My first guess is that it's a deadlock caused by a blocking call of
Result
inRequestPipe.cs
which interfered with the way IIS is handling tasks.The text was updated successfully, but these errors were encountered: