diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations/Session/HttpSessionController.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Session/HttpSessionController.cs | 22 |
1 files changed, 19 insertions, 3 deletions
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<string, string>(), cancellationToken); } - private async Task SendMessage(string name, - Dictionary<string, string> args, + private async Task SendMessage(string name, + Dictionary<string, string> args, CancellationToken cancellationToken) { var url = PostUrl + "/" + name + ToQueryString(args); |
