jjchiw / gelf4net

GELF log4net Appender - graylog2
MIT License
63 stars 59 forks source link

Not awaited async call causes upredictable crashes of application #35

Closed remunda closed 7 years ago

remunda commented 8 years ago

There's not awaited call which can cause random crash of Web application.

[InvalidOperationException: An asynchronous module or handler completed while an asynchronous operation was still pending.]

https://github.com/jjchiw/gelf4net/blob/master/src/Gelf4net/Appender/GelfHttpAppender.cs#L48

jjchiw commented 8 years ago

Hi

The WebClient.UploadStringAsync is not awaitable.

Do you have a Stacktrace with the exception?

karthiksprakash commented 7 years ago

You could use WebClient.UploadStringTaskAsync() instead or even HttpClient altogether. There isn't much stack trace available with this error. It's something that is not even easily captured.

Not awaiting lets the Controller action method complete at which point, ASP.NET realizes this logging thread is still active and throws this exception.

So essentially, this error manifests in an API call that completes quick than the logging can post the string. This occurs in most of the action methods in one of my apps, so I had to temporarily disable logging.

jjchiw commented 7 years ago

Hi

Since the library targets framework v4.0 we cannot use HttpClient in the main package of gelf4net there is a package a standalone library that uses HttpClient.

During the weeked I'll make some tests and change WebClient.UploadStringAsync to WebClient.UploadStringTaskAsync()

And I'll update the License in order to close this issue https://github.com/jjchiw/gelf4net/issues/40

jjchiw commented 7 years ago

Ok I decided to remove support for framework 4.0.....

So everything is now with HttpClient