From 3c48def0d76417572193cd306846f1516e0e9038 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 16 Dec 2014 00:01:57 -0500 Subject: sync updates --- .../Session/HttpSessionController.cs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Session/HttpSessionController.cs') diff --git a/MediaBrowser.Server.Implementations/Session/HttpSessionController.cs b/MediaBrowser.Server.Implementations/Session/HttpSessionController.cs index d2ace23a9..4a64d3753 100644 --- a/MediaBrowser.Server.Implementations/Session/HttpSessionController.cs +++ b/MediaBrowser.Server.Implementations/Session/HttpSessionController.cs @@ -25,6 +25,7 @@ namespace MediaBrowser.Server.Implementations.Session private readonly string _postUrl; private Timer _pingTimer; + private DateTime _lastPingTime; public HttpSessionController(IHttpClient httpClient, IJsonSerializer json, @@ -68,10 +69,23 @@ namespace MediaBrowser.Server.Implementations.Session try { await SendMessage("Ping", CancellationToken.None).ConfigureAwait(false); + + _lastPingTime = DateTime.UtcNow; } catch { - ReportSessionEnded(); + var lastActivityDate = new[] { _lastPingTime, Session.LastActivityDate } + .Max(); + + var timeSinceLastPing = DateTime.UtcNow - lastActivityDate; + + // We don't want to stop the session due to one single request failure + // At the same time, we don't want the timeout to be too long because it will + // be sitting in active sessions available for remote control, when it's not + if (timeSinceLastPing >= TimeSpan.FromMinutes(5)) + { + ReportSessionEnded(); + } } } @@ -90,6 +104,8 @@ namespace MediaBrowser.Server.Implementations.Session { if (_pingTimer != null) { + _lastPingTime = DateTime.UtcNow; + var period = TimeSpan.FromSeconds(60); _pingTimer.Change(period, period); @@ -101,8 +117,8 @@ namespace MediaBrowser.Server.Implementations.Session return SendMessage(name, new Dictionary(), cancellationToken); } - private async Task SendMessage(string name, - Dictionary args, + private async Task SendMessage(string name, + Dictionary args, CancellationToken cancellationToken) { var url = PostUrl + "/" + name + ToQueryString(args); -- cgit v1.2.3