aspnet / AspNetWebStack

ASP.NET MVC 5.x, Web API 2.x, and Web Pages 3.x (not ASP.NET Core)
Other
858 stars 354 forks source link

PushStreamContent does not use ConfigureAwait(false) #208

Closed paulhickman-a365 closed 6 years ago

paulhickman-a365 commented 6 years ago

In PushStreamContent.cs the method SerializeToStreamAsync performs two awaits but does not use ConfigureAwait(false) which means it tries to re-acquire the calling the thread context.

This is causing a threading deadlock in my unit tests. Is this intentional behaviour, or an oversight?

dougbu commented 6 years ago

Are you calling into this code from a synchronous context? If yes, change your unit test to itself be async. If no, call ConfigureAwait(false) in the unit test. Please let us know if this resolves your hangs.

Separately, the legacy ASP.NET code does not call ConfigureAwait(...) anywhere and could break existing applications if that changes -- especially (as is possible in PushStreamContent) when awaiting user code.

paulhickman-a365 commented 6 years ago

Turned out to be a red herring - the unit test wasn't closing the stream which caused SerializeToStreamAsync to not return.