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

HttpEventCollectorSender FlushAsync task is not started and thus cannot be awaited unless manually started #51

Open
seanmarthur opened this issue Mar 14, 2019 · 2 comments

Comments

@seanmarthur
Copy link

I believe the FlushAsync method is implemented incorrectly:

https://github.com/splunk/splunk-library-dotnetlogging/blob/master/src/Splunk.Logging.Common/HttpEventCollectorSender.cs#L292-L298

There are examples on the web (see here) showing the usage as:

await ecSender.FlushAsync();

However, when trying to run such a sample, the application hangs forever at this line. This is because the underling task never starts. The proper usage as the code currently is would be:

var flushTask = ecSender.FlushAsync();
flushTask.Start();
await flushTask;

However the consumer should not need to start this task manually - it should be returned from FlushAsync in a started state.

Refactored FlushAsync example:

    public Task FlushAsync()
    {
      var task = new Task(() =>
     {
       FlushSync();
     });
      task.Start();
      return task;
    }
@shakeelmohamed
Copy link
Contributor

Hi @seanmarthur,

We're open to a pull request to address this issue if you're interested. Thanks for the note

@bluedog13
Copy link

bluedog13 commented Jun 21, 2021

"This is because the underling task never starts"

I've seen the POST commands happening behind the scenes, but the control never returns back to the method calling the "FlushAsync()".

@seanmarthur - what you have observed is a very valid observation and is indeed an issue that I too have faced.

It may also help if the return type has an object with some information about the completed work and not just "Task" itself. We have no insight to what success really means unless we capture the exception and infer the results.

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

No branches or pull requests

3 participants