Fix session timeout due to timestamp frequency mismatch and activity tracking (#1106)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
This commit is contained in:
Copilot 2025-12-15 16:21:21 -05:00 • committed by GitHub
commit aaffd71c69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -521,6 +521,33 @@ public class StreamableHttpServerConformanceTests(ITestOutputHelper outputHelper
Assert.StartsWith("MaxIdleSessionCount of 2 exceeded. Closing idle session", idleLimitLogMessage.Message);
}
[Fact]
public async Task ActiveSession_WithPeriodicRequests_DoesNotTimeout()
{
var fakeTimeProvider = new FakeTimeProvider();
Builder.Services.AddMcpServer().WithHttpTransport(options =>
{
options.IdleTimeout = TimeSpan.FromHours(2);
options.TimeProvider = fakeTimeProvider;
});
await StartAsync();
await CallInitializeAndValidateAsync();
// Simulate multiple POST requests over a period longer than IdleTimeout
// Each request should update LastActivityTicks, preventing timeout
for (int i = 0; i < 5; i++)
{
// Advance time by 1 hour between requests
fakeTimeProvider.Advance(TimeSpan.FromHours(1));
await CallEchoAndValidateAsync();
}
// Total time elapsed: 5 hours (> 2 hour IdleTimeout)
// But session should still be alive because of periodic activity
await CallEchoAndValidateAsync();
}
[Fact]
public async Task McpServer_UsedOutOfScope_CanSendNotifications()
{