datalust / seq-extensions-logging

Add centralized log collection to ASP.NET Core apps with one line of code.
https://datalust.co/seq
Apache License 2.0
84 stars 12 forks source link

Use of async void leading to InvalidOperationException on ASP.NET WebForms #40

Closed ShutterQuick closed 3 years ago

ShutterQuick commented 3 years ago

Hi,

An asynchronous module or handler completed while an asynchronous operation was still pending.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: An asynchronous module or handler completed while an asynchronous operation was still pending.

This use of async void prevents the task to be properly tracked by the ASP.NET WebForms. Relevant info: https://stackoverflow.com/a/17660475

https://github.com/datalust/seq-extensions-logging/blob/93dd71fc5fd26642c32a41d01cee2b5603de97f2/src/Seq.Extensions.Logging/Serilog/Sinks/PeriodicBatching/PortableTimer.cs#L127

It's not immediately obvious to me what the purpose of doing it like this is. Could you have a look at it, and consider removing AsObserved() and instead just do .ConfigureAwait(false) directly?

https://github.com/datalust/seq-extensions-logging/blob/93dd71fc5fd26642c32a41d01cee2b5603de97f2/src/Seq.Extensions.Logging/Serilog/Sinks/PeriodicBatching/PortableTimer.cs#L54

I've tested doing that, and it makes my problem go away.

nblumhardt commented 3 years ago

Thanks for the heads-up - this code was originally derived from Serilog.Sinks.PeriodicBatching, which has subsequently been updated to fix a few issues like this. We'll re-import the Serilog version of the code, which no longer includes the problematic section đź‘Ť

nblumhardt commented 3 years ago

@ShutterQuick there should be a 6.0.0-dev-* version published to NuGet with this fix in just a moment. It would be great to hear how it goes for you. Thanks again!

ShutterQuick commented 3 years ago

Thank you for the super quick turnaround! Looks like it's working properly now for my use case, thanks a lot!