Skip to content

Can we avoid running IdleTrackingBackgroundService if HTTP Server transport is configured as stateless? #1515

@srogovtsev

Description

@srogovtsev

From what I can see in the code, IdleTrackingBackgroundService will check for sessions to clear even if server is configured as stateless - which seems somewhat wasteful if we know that there'll never be an open session to clear. This is probably even more relevant after 1.2.0 which pushes to "stateless by default".

var timeProvider = _options.Value.TimeProvider;
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(5), timeProvider);
while (!stoppingToken.IsCancellationRequested && await timer.WaitForNextTickAsync(stoppingToken))
{
await _sessions.PruneIdleSessionsAsync(stoppingToken);
}

The fix seems to be as simple as overriding StartAsync:

public override Task StartAsync(CancellationToken cancellationToken)
{
  if (_options.Value.Stateless)
    return Task.CompletedTask;

  return base.StartAsync(cancellationToken);
}

PS I've asked this in the discussions space (#1485), but as there was no response, I'm not sure it was a proper place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions