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.
From what I can see in the code,
IdleTrackingBackgroundServicewill 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".csharp-sdk/src/ModelContextProtocol.AspNetCore/IdleTrackingBackgroundService.cs
Lines 38 to 44 in 54caccc
The fix seems to be as simple as overriding
StartAsync: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.