Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log.CloseAndFlush() deadlock on AWS Lambda #167

Closed
nikoudel opened this issue Feb 8, 2022 · 6 comments
Closed

Log.CloseAndFlush() deadlock on AWS Lambda #167

nikoudel opened this issue Feb 8, 2022 · 6 comments
Labels

Comments

@nikoudel
Copy link

nikoudel commented Feb 8, 2022

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:

LoggerTimeout

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.

@nblumhardt
Copy link
Member

Thanks for the report, we'll dig in 👍

@nblumhardt nblumhardt changed the title Log.CloseAndFlush() deadlock Log.CloseAndFlush() deadlock on AWS Lambda Mar 7, 2022
@nblumhardt nblumhardt changed the title Log.CloseAndFlush() deadlock on AWS Lambda Log.CloseAndFlush() deadlock on AWS Lambda Mar 7, 2022
@DarkMio
Copy link

DarkMio commented Sep 9, 2022

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.

@nblumhardt
Copy link
Member

Hi @DarkMio - thanks for reaching out. Starting work on a proper fix for this now via serilog/serilog#1750.

@DarkMio
Copy link

DarkMio commented Sep 9, 2022

Very cool, that was just in time. Thanks @nblumhardt!

@nblumhardt
Copy link
Member

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!

@nblumhardt
Copy link
Member

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:

serilog/serilog-extensions-hosting#67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants