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

Investigation hanging audit instance #4758

Draft
wants to merge 10 commits into
base: otel-metrics
Choose a base branch
from

Conversation

ramonsmits
Copy link
Member

No description provided.

@ramonsmits ramonsmits force-pushed the fix-hanging-ingestion branch from eb85f65 to 3f15bee Compare February 3, 2025 12:52
@ramonsmits ramonsmits changed the base branch from master to otel-metrics February 3, 2025 12:57
@ramonsmits ramonsmits force-pushed the fix-hanging-ingestion branch from 3f15bee to fd0df00 Compare February 3, 2025 13:14
}

public Task StartAsync(CancellationToken _) => watchdog.Start(() => applicationLifetime.StopApplication());
public async Task StartAsync(CancellationToken cancellationToken)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreasohlund @danielmarbach Alternative is to use BackgroundService.ExecuteAsync, assuming we can safely terminate ASAP:

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
    await watchdog.Start(() => applicationLifetime.StopApplication());
    await Loop(stoppingToken);
    // Intentionally not invoking the following to shut down ASAP
    // watchdog.Stop();
    // channel.Writer.Complete();
    // if (transportInfrastructure != null)
    // {
    //     await transportInfrastructure.Shutdown(stoppingToken);
    // }
}

As everything is at-least-once processing and idempotent this would be the fastest method to shutdow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to switch to a BackgroundService here and inline the loop into the execute method

Be aware though of dotnet/runtime#36063 and https://blog.stephencleary.com/2020/05/backgroundservice-gotcha-startup.html for more context

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I already tested that and it works. As the loop pretty much immediately does IO its not affected which is why I removed the Task.Run. I can restore it for safety or add a code comment. Any preference @danielmarbach ?

catch (Exception e) // show must go on
{
if (logger.IsInfoEnabled)
catch (OperationCanceledException e) when (e.CancellationToken == cancellationToken)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreasohlund please review todays commits seperately and then combined.

@ramonsmits ramonsmits removed the request for review from andreasohlund February 4, 2025 15:53
Fixed by properly handling Stop/Start CancellationTokens and validating thrown OCE against host token and added fatal exception handling.
@ramonsmits ramonsmits force-pushed the fix-hanging-ingestion branch from 21ffe9c to d8d5730 Compare February 4, 2025 16:28
{
var timedCancellationSource = new CancellationTokenSource(databaseConfiguration.BulkInsertCommitTimeout);
var timedCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have a comment here indicating the disposal happens as part of the unit of work

}

auditBatchSize.Record(contexts.Count);
var sw = Stopwatch.StartNew();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not relevant for this PR but we should be using a ValueStopWatch here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

public Task StartAsync(CancellationToken _) => watchdog.Start(() => applicationLifetime.StopApplication());
public async Task StartAsync(CancellationToken cancellationToken)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to switch to a BackgroundService here and inline the loop into the execute method

Be aware though of dotnet/runtime#36063 and https://blog.stephencleary.com/2020/05/backgroundservice-gotcha-startup.html for more context

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

Successfully merging this pull request may close these issues.

3 participants