Skip to content

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
public async ValueTask<IAuditIngestionUnitOfWork> StartNew(int batchSize, CancellationToken cancellationToken)
{
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

@ramonsmits ramonsmits force-pushed the fix-hanging-ingestion branch from e87f040 to a2f471e Compare February 6, 2025 00:49
Base automatically changed from otel-metrics to master February 10, 2025 07:52
@ramonsmits
Copy link
Member Author

@ramonsmits ramonsmits closed this Feb 17, 2025
@bording bording deleted the fix-hanging-ingestion branch April 28, 2025 19:59
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.

4 participants