serilog-sinks-seq
serilog-sinks-seq copied to clipboard
`Log.CloseAndFlush()` deadlock on AWS Lambda
Log.CloseAndFlush()
seems to be deadlocking when run in AWS Lambda and my Seq server instance goes down for some (irrelevant) reason making Seq a single point of failure for the whole microservice gang. This is how it looks like in the logs:
This only happens when running in AWS Lambda environment. In a console app execution continues after a graceful timeout of ~4 seconds. I suspect it might be related to this and followed this advice to make it behave better:
...
finally
{
Task.Run(Log.CloseAndFlush).Wait(1000);
}
It works but still looks like a hack.
Thanks for the report, we'll dig in 👍
We're affected by the same problem. CloseAndFlush
causes in non-debug environments to deadlock. One of our engineers pointed out that a lock and tasks cause tasks running in a sync context - which then deadlocks by accident.
This only happens with a config in which the seq sink is added, the others we use (console, eventlog) are unaffected.
Hi @DarkMio - thanks for reaching out. Starting work on a proper fix for this now via https://github.com/serilog/serilog/pull/1750.
Very cool, that was just in time. Thanks @nblumhardt!
Hi @DarkMio; v5.2.0 is out now and includes this fix. I'll close the ticket as completed but if you notice any ongoing issues please let us know!
Ah sorry, also, for this to work you'll need to asynchronously dispose the Serilog Logger
. If you're using var logger = new LoggerConfiguration().CreateLogger()
that maps to await using
; otherwise, using the Log
class it's await Log.CloseAndFlushAsync()
.
If you're on Serilog.AspNetCore and configuring Serilog in the UseSerilog(lc => ...)
callback, you'll need:
https://github.com/serilog/serilog-extensions-hosting/issues/67