Skip to content

Bug - Dispose() doesn't wait for messages to be sent to the database before terminating resulting in possible log losses #24

@fbedogni

Description

@fbedogni

Problem
The application terminates before the sink has finished uploading the logs to the database.

To reproduce
Create a small console app in which you create a logger, log something, dispose the logger and exit.
Most of the time the application will terminate almost istantly and the log won't be written to the database.

Source of the bug
In the constructor of the class BatchProvider the task _batchTask, which is responsible for sending logs, is initialized using the Task.Factory.StartNew
image
This task should be completed only when all the logs have been written to the database, but it's not the case.
This causes the Task.WaitAll in the Dispose() method to return before all the logs have been written to the database
To make sure that _batchTask waits for all the internal tasks to finish you need to call the Unwrap() method.
This SO explains it better than i can task-factory-startnew-wont-wait-for-task-completion

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions